|
||||||||||
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.
for license details.
The copyright to this program is held by it's authors.
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 Logger |
log
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 instansiated |
Method Summary | |
---|---|
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)
|
static long |
getLastModified(URI uri,
String proxyHost,
Integer proxyPort)
|
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)
|
static boolean |
isNewer(URI left,
URI right,
String proxyHost,
Integer proxyPort)
|
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,
URIFilter filter)
List all the files specified by the index file passed in. |
static Properties |
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(Properties 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 Logger log
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
public static void makeFile(URI orig) throws MalformedURLException, IOException
orig
- The file URI to create
MalformedURLException
IOException
public 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 move(URI oldUri, URI newUri) throws IOException
oldUri
- The URI to movenewUri
- The desitination URI
IOException
public static boolean delete(URI orig) throws IOException
orig
- The URI to delete
IOException
public static File getAsFile(URI uri) throws IOException
uri
- The original URI to the file.
IOException
public 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
public static OutputStream getOutputStream(URI uri) throws IOException
uri
- The URI to attempt to write to
IOException
public 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
public 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.
MalformedURLException
IOException
public static String[] listByFile(URI uri, URIFilter filter) throws MalformedURLException
MalformedURLException
public static String[] listByIndexFile(URI index, URIFilter filter) throws IOException
FileNotFoundException
IOException
public static Properties loadProperties(URI uri) throws IOException
uri
- the location of the properties
IOException
public static void storeProperties(Properties 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
public 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)
public static long getLastModified(URI uri, String proxyHost)
public static long getLastModified(URI uri, String proxyHost, Integer proxyPort)
public static boolean isNewer(URI left, URI right)
left
- right
-
public static boolean isNewer(URI left, URI right, String proxyHost)
public static boolean isNewer(URI left, URI right, String proxyHost, Integer proxyPort)
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()
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-2007 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |