|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.crosswire.common.util.NetUtil
public class NetUtil
The NetUtil class looks after general utility stuff around the java.net package.
|
Distribution Licence: JSword is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The License is available on the internet here, or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA The copyright to this program is held by it's authors. |
Licence| Nested Class Summary | |
|---|---|
static class |
NetUtil.IsDirectoryURLFilter
Check that the directories in the version directory really represent versions. |
static class |
NetUtil.URLFilterFilenameFilter
Quick implementation of FilenameFilter that uses a URLFilter |
| 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 |
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 |
static String |
PROTOCOL_FTP
Constant for the file: protocol |
static String |
PROTOCOL_HTTP
Constant for the file: protocol |
static String |
PROTOCOL_JAR
Constant for the jar: protocol |
static String |
SEPARATOR
URL 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 | |
|---|---|
private static void |
checkFileURL(URL url)
Throw if the given URL does not use the 'file:' protocol |
static boolean |
delete(URL orig)
Delete a URL. |
static File |
getAsFile(URL url)
Return a File from the URL either by extracting from a file: URL or by downloading to a temp dir first |
static long |
getLastModified(URL url)
When was the given URL last modified. |
static OutputStream |
getOutputStream(URL url)
Attempt to obtain an OutputStream from a URL. |
static OutputStream |
getOutputStream(URL url,
boolean append)
Attempt to obtain an OutputStream from a URL. |
static int |
getSize(URL url)
|
static URL |
getTemporaryURL(String prefix,
String suffix)
A URL version of File.createTempFile() |
static URL |
getURL(File file)
Get a URL version of the given file. |
static File |
getURLCacheDir()
Returns the URLCacheDir. |
static boolean |
isDirectory(URL orig)
If there is a directory at the other end of this URL return true. |
static boolean |
isFile(URL url)
If there is a file at the other end of this URL return true. |
static boolean |
isNewer(URL left,
URL right)
Returns whether the left is newer than the right by comparing their last modified dates. |
private static boolean |
isSeparator(char c)
|
static URL |
lengthenURL(URL orig,
String extra)
Utility to add a string to the end of a URL. |
static String[] |
list(URL url,
URLFilter filter)
List the items available assuming that this URL points to a directory. |
static String[] |
listByFile(URL url,
URLFilter filter)
List all the files specified by the index file passed in. |
static String[] |
listByIndexFile(URL index,
URLFilter filter)
List all the files specified by the index file passed in. |
static void |
makeDirectory(URL orig)
If the directory does not exist, create it. |
static void |
makeFile(URL orig)
If the file does not exist, create it. |
static boolean |
move(URL oldUrl,
URL newUrl)
Move a URL from one place to another. |
static void |
setURLCacheDir(File cachedir)
Sets the cache directory. |
static URL |
shortenURL(URL orig,
String strip)
Utility to strip a string from the end of a 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 void makeDirectory(URL orig)
throws MalformedURLException
orig - The URL to check
MalformedURLException
public static void makeFile(URL orig)
throws MalformedURLException,
IOException
orig - The URL to check
MalformedURLException
IOExceptionpublic static boolean isFile(URL url)
url - The URL to check
public static boolean isDirectory(URL orig)
orig - The URL to check
public static boolean move(URL oldUrl,
URL newUrl)
throws IOException
oldUrl - The URL to movenewUrl - The desitination URL
IOException
public static boolean delete(URL orig)
throws IOException
orig - The URL to delete
IOException
public static File getAsFile(URL url)
throws IOException
url - The original URL to the file.
IOException
public static URL shortenURL(URL orig,
String strip)
throws MalformedURLException
orig - The URL to stripstrip - The text to strip from the end of the URL
MalformedURLException - If the URL does not end in the given text
public static URL lengthenURL(URL orig,
String extra)
orig - The URL to stripextra - The text to add to the end of the URL
private static boolean isSeparator(char c)
public static OutputStream getOutputStream(URL url)
throws IOException
url - The URL to attempt to write to
IOException
public static OutputStream getOutputStream(URL url,
boolean append)
throws IOException
url - The URL to attempt to write toappend - Do we write to the end of the file instead of the beginning
IOException
public static String[] list(URL url,
URLFilter filter)
throws MalformedURLException,
IOException
There are 2 methods of calculating the answer - if the URL is a file: URL 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 URL is a file: URL 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(URL url,
URLFilter filter)
throws MalformedURLException
MalformedURLException
public static String[] listByIndexFile(URL index,
URLFilter filter)
throws IOException
IOExceptionpublic static int getSize(URL url)
url - the resource whose size is wanted
public static long getLastModified(URL url)
public static boolean isNewer(URL left,
URL right)
left - right -
private static void checkFileURL(URL url)
throws MalformedURLException
url - The URL to check
MalformedURLException - If the protocol is not file:public static File getURLCacheDir()
public static void setURLCacheDir(File cachedir)
cachedir - The URLCacheDir to setpublic static URL getURL(File file)
file - The File to turn into a URL
public static URL getTemporaryURL(String prefix,
String suffix)
throws IOException
File.createTempFile()
IOException - If something goes wrong creating the temp URL
|
Copyright ? 2003-2004 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||