|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.common.util.NetUtil
public final class NetUtil
The NetUtil class looks after general utility stuff around the java.net package.
The GNU Lesser General Public License for details.
Nested Class Summary | |
---|---|
static class |
NetUtil.IsDirectoryURIFilter
Check that the directories in the version directory really represent versions. |
static class |
NetUtil.URIFilterFilenameFilter
Quick implementation of FilenameFilter that uses a URIFilter |
Field Summary | |
---|---|
static String |
AUTH_SEPERATOR_PASSWORD
Separating the password from the username |
static String |
AUTH_SEPERATOR_USERNAME
Separating the username from the rest of the URL/URI |
private static File |
cachedir
Where are temporary files cached. |
static String |
INDEX_FILE
For directory listings |
private static org.slf4j.Logger |
LOGGER
The log stream |
static String |
PROTOCOL_FILE
Constant for the file: protocol or scheme |
static String |
PROTOCOL_FTP
Constant for the ftp: protocol or scheme |
static String |
PROTOCOL_HTTP
Constant for the http: protocol or scheme |
static String |
PROTOCOL_JAR
Constant for the jar: protocol or scheme |
static String |
SEPARATOR
URL/URI separator |
private static String |
TEMP_SUFFIX
The temporary suffix, used when a temporary file is needed in the system's temporary directory. |
Constructor Summary | |
---|---|
private |
NetUtil()
Basic constructor - ensure that we can't be instantiated |
Method Summary | |
---|---|
static boolean |
canRead(URI orig)
If there is a readable directory or file at the other end of this URI return true. |
static boolean |
canWrite(URI orig)
If there is a writable directory or file at the other end of this URI return true. |
private static void |
checkFileURI(URI uri)
Throw if the given URI does not use the 'file:' protocol |
static URI |
copy(URI uri)
|
static boolean |
delete(URI orig)
Delete a URI. |
static File |
getAsFile(URI uri)
Return a File from the URI either by extracting from a file: URI or by downloading to a temp dir first |
static InputStream |
getInputStream(URI uri)
Attempt to obtain an InputStream from a URI. |
static long |
getLastModified(URI uri)
When was the given URI last modified. |
static long |
getLastModified(URI uri,
String proxyHost)
When was the given URI last modified. |
static long |
getLastModified(URI uri,
String proxyHost,
Integer proxyPort)
When was the given URI last modified. |
static OutputStream |
getOutputStream(URI uri)
Attempt to obtain an OutputStream from a URI. |
static OutputStream |
getOutputStream(URI uri,
boolean append)
Attempt to obtain an OutputStream from a URI. |
static int |
getSize(URI uri)
|
static int |
getSize(URI uri,
String proxyHost)
|
static int |
getSize(URI uri,
String proxyHost,
Integer proxyPort)
|
static URI |
getTemporaryURI(String prefix,
String suffix)
A URI version of File.createTempFile() |
static URI |
getURI(File file)
Get a URI version of the given file. |
static File |
getURICacheDir()
Returns the cache directory. |
static boolean |
isDirectory(URI orig)
If there is a directory at the other end of this URI return true. |
static boolean |
isFile(URI uri)
If there is a file at the other end of this URI return true. |
static boolean |
isNewer(URI left,
URI right)
Returns whether the left is newer than the right by comparing their last modified dates. |
static boolean |
isNewer(URI left,
URI right,
String proxyHost)
Returns whether the left is newer than the right by comparing their last modified dates. |
static boolean |
isNewer(URI left,
URI right,
String proxyHost,
Integer proxyPort)
Returns whether the left is newer than the right by comparing their last modified dates. |
private static boolean |
isSeparator(char c)
|
static URI |
lengthenURI(URI orig,
String anExtra)
Utility to add a string to the end of a URI. |
static String[] |
list(URI uri,
URIFilter filter)
List the items available assuming that this URI points to a directory. |
static String[] |
listByFile(URI uri,
URIFilter filter)
List all the files specified by the index file passed in. |
static String[] |
listByIndexFile(URI index)
List all the strings specified by the index file passed in. |
static String[] |
listByIndexFile(URI index,
URIFilter filter)
List all the files specified by the index file passed in. |
static PropertyMap |
loadProperties(URI uri)
Load up properties given by a URI. |
static void |
makeDirectory(URI orig)
If the directory does not exist, create it. |
static void |
makeFile(URI orig)
If the file does not exist, create it. |
static boolean |
move(URI oldUri,
URI newUri)
Move a URI from one place to another. |
static void |
setURICacheDir(File cachedir)
Sets the cache directory. |
static URI |
shortenURI(URI orig,
String strip)
Utility to strip a string from the end of a URI. |
static void |
storeProperties(PropertyMap properties,
URI uri,
String title)
Store the properties at the location given by the uri using the supplied title. |
static URI |
toURI(URL url)
Convert an URL to an URI. |
static URL |
toURL(URI uri)
Convert an URI to an URL. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PROTOCOL_FILE
public static final String PROTOCOL_HTTP
public static final String PROTOCOL_FTP
public static final String PROTOCOL_JAR
public static final String INDEX_FILE
public static final String SEPARATOR
public static final String AUTH_SEPERATOR_USERNAME
public static final String AUTH_SEPERATOR_PASSWORD
private static final String TEMP_SUFFIX
private static File cachedir
private static final org.slf4j.Logger LOGGER
Constructor Detail |
---|
private NetUtil()
Method Detail |
---|
public static URI copy(URI uri)
public static void makeDirectory(URI orig) throws MalformedURLException
orig
- The directory URI to create
MalformedURLException
- If the URI is not validpublic static void makeFile(URI orig) throws MalformedURLException, IOException
orig
- The file URI to create
MalformedURLException
- If the URI is not valid
IOException
- a problem with I/O happenedpublic static boolean isFile(URI uri)
uri
- The URI to check
public static boolean isDirectory(URI orig)
orig
- The URI to check
public static boolean canWrite(URI orig)
orig
- The URI to check
public static boolean canRead(URI orig)
orig
- The URI to check
public static boolean move(URI oldUri, URI newUri) throws IOException
oldUri
- The URI to movenewUri
- The destination URI
IOException
- a problem with I/O happenedpublic static boolean delete(URI orig) throws IOException
orig
- The URI to delete
IOException
- a problem with I/O happenedpublic static File getAsFile(URI uri) throws IOException
uri
- The original URI to the file.
IOException
- a problem with I/O happenedpublic static URI shortenURI(URI orig, String strip) throws MalformedURLException
orig
- The URI to stripstrip
- The text to strip from the end of the URI
MalformedURLException
- If the URI does not end in the given textpublic static URI lengthenURI(URI orig, String anExtra)
orig
- The URI to lengthenanExtra
- The text to add to the end of the URI
private static boolean isSeparator(char c)
public static InputStream getInputStream(URI uri) throws IOException
uri
- The URI to attempt to read from
IOException
- a problem with I/O happenedpublic static OutputStream getOutputStream(URI uri) throws IOException
uri
- The URI to attempt to write to
IOException
- a problem with I/O happenedpublic static OutputStream getOutputStream(URI uri, boolean append) throws IOException
uri
- The URI to attempt to write toappend
- Do we write to the end of the file instead of the beginning
IOException
- a problem with I/O happenedpublic static String[] list(URI uri, URIFilter filter) throws MalformedURLException, IOException
There are 2 methods of calculating the answer - if the URI is a file: URI then we can just use File.list(), otherwise we ask for a file inside the directory called index.txt and assume the directories contents to be listed one per line.
If the URI is a file: URI then we execute both methods and warn if there is a difference, but returning the values from the index.txt method.
uri
- the URI to listfilter
- the filter for the listing
MalformedURLException
- If the URI is not valid
IOException
- a problem with I/O happenedpublic static String[] listByFile(URI uri, URIFilter filter) throws MalformedURLException
uri
- the URI to listfilter
- the filter for the listing
MalformedURLException
- If the URI is not validpublic static String[] listByIndexFile(URI index) throws IOException
index
- the URI to list
IOException
- a problem with I/O happenedpublic static String[] listByIndexFile(URI index, URIFilter filter) throws IOException
Each line is pre-processed:
index
- the URI to listfilter
- the filter for the listing
IOException
- a problem with I/O happenedpublic static PropertyMap loadProperties(URI uri) throws IOException
uri
- the location of the properties
IOException
- a problem with I/O happenedpublic static void storeProperties(PropertyMap properties, URI uri, String title) throws IOException
properties
- the properties to storeuri
- the location of the storetitle
- the label held in the properties file
IOException
- a problem with I/O happenedpublic static int getSize(URI uri)
uri
- the resource whose size is wanted
public static int getSize(URI uri, String proxyHost)
public static int getSize(URI uri, String proxyHost, Integer proxyPort)
public static long getLastModified(URI uri)
uri
- the URI to examine
public static long getLastModified(URI uri, String proxyHost)
uri
- the URI to examineproxyHost
- the proxy host
public static long getLastModified(URI uri, String proxyHost, Integer proxyPort)
uri
- the URI to examineproxyHost
- the proxy hostproxyPort
- the proxy port
public static boolean isNewer(URI left, URI right)
left
- one URI to compareright
- the other URI to compare
public static boolean isNewer(URI left, URI right, String proxyHost)
left
- one URI to compareright
- the other URI to compareproxyHost
- the proxy host
public static boolean isNewer(URI left, URI right, String proxyHost, Integer proxyPort)
left
- one URI to compareright
- the other URI to compareproxyHost
- the proxy hostproxyPort
- the proxy port
private static void checkFileURI(URI uri) throws MalformedURLException
uri
- The URI to check
MalformedURLException
- If the protocol is not file:public static File getURICacheDir()
public static void setURICacheDir(File cachedir)
cachedir
- The cache directory to setpublic static URI getURI(File file)
file
- The File to turn into a URI
public static URI getTemporaryURI(String prefix, String suffix) throws IOException
File.createTempFile()
prefix
- the prefix of the temporary filesuffix
- the suffix of the temporary file
IOException
- If something goes wrong creating the temp URIpublic static URI toURI(URL url)
url
- to convert
public static URL toURL(URI uri)
uri
- to convert
|
Copyright ยจ 2003-2015 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |