|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jivesoftware.spark.util.URLFileSystem
public class URLFileSystem
URLFileSystem
class handles some of the most common
functionallity when working with URLs.
Constructor Summary | |
---|---|
URLFileSystem()
|
Method Summary | |
---|---|
boolean |
canCreate(java.net.URL url)
Tests whether the application can create the resource at the specified URL . |
java.net.URL |
canonicalize(java.net.URL url)
Returns a canonical form of the URL , if one is available. |
boolean |
canRead(java.net.URL url)
Tests whether the application can read the resource at the specified URL . |
boolean |
canWrite(java.net.URL url)
Tests whether the application can modify the resource at the specified URL . |
static void |
copy(java.io.InputStream in,
java.io.OutputStream out)
Common code for copy routines. |
static void |
copy(java.net.URL src,
java.io.File dst)
Copies the contents at src to dst . |
static boolean |
exists(java.net.URL url)
Returns true if the specified URL points to a
resource that currently exists; returns false
otherwise. |
static java.lang.String |
getContents(java.io.File file)
Returns the contents of a file. |
static java.lang.String |
getContents(java.io.InputStream is)
|
static java.lang.String |
getContents(java.net.URL url)
Returns the contents of a given URL. |
static java.lang.String |
getFileName(java.net.URL url)
Returns the name of the file contained by the URL , not
including any protocol, hostname authentication, directory path,
anchor, or query. |
long |
getLength(java.net.URL url)
Returns the number of bytes contained in the resource that the specified URL points to. |
static java.lang.String |
getName(java.net.URL url)
Returns the name of the file contained by the URL , not
including any protocol, hostname authentication, directory path,
anchor, or query. |
static java.net.URL |
getParent(java.net.URL url)
|
java.lang.String |
getPath(java.net.URL url)
Returns the path part of the URL . |
java.lang.String |
getPathNoExt(java.net.URL url)
Returns the path part of the URL without the last file
extension. |
java.lang.String |
getPlatformPathName(java.net.URL url)
Returns the platform-dependent String representation of the URL ; the returned string should be considered acceptable
for users to read. |
static java.lang.String |
getSuffix(java.net.URL url)
If a dot ('.') occurs in the path portion of the URL , then
all of the text starting at the last dot is returned, including
the dot. |
boolean |
isValid(java.net.URL url)
Tests whether the specified URL is valid. |
static boolean |
mkdirs(java.net.URL url)
|
static java.net.URL |
newFileURL(java.io.File file)
|
static java.net.URL |
newFileURL(java.lang.String filePath)
|
static java.net.URL |
newURL(java.lang.String protocol,
java.lang.String path)
|
static java.net.URL |
newURL(java.lang.String protocol,
java.lang.String userinfo,
java.lang.String host,
int port,
java.lang.String path,
java.lang.String query,
java.lang.String ref)
Creates a new URL whose parts have the exact values that
are specified. |
static java.io.File |
url2File(java.net.URL url)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public URLFileSystem()
Method Detail |
---|
public static java.lang.String getContents(java.net.URL url)
url
- the url.
public static java.lang.String getContents(java.io.File file)
file
- the file whose contents you wish to retrieve.
public static java.lang.String getContents(java.io.InputStream is)
public static void copy(java.net.URL src, java.io.File dst) throws java.io.IOException
src
to dst
.
java.io.IOException
public static void copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static java.lang.String getSuffix(java.net.URL url)
URL
, then
all of the text starting at the last dot is returned, including
the dot. If the last dot is also the last character in the path,
then the dot by itself is returned. If there is no dot in the
path, then the empty string is returned.
public java.net.URL canonicalize(java.net.URL url)
URL
, if one is available.
The default implementation just returns the specified URL
as-is.
public boolean canRead(java.net.URL url)
URL
.
true
if and only if the specified
URL
points to a resource that exists and can be
read by the application; false
otherwise.public boolean canWrite(java.net.URL url)
URL
.
true
if and only if the specified
URL
points to a file that exists and the
application is allowed to write to the file; false
otherwise.public boolean canCreate(java.net.URL url)
URL
.
true
if the resource at the specified URL
exists or can be created; false
otherwise.public boolean isValid(java.net.URL url)
URL
is valid. If the resource
pointed by the URL
exists the method returns true
.
If the resource does not exist, the method tests that all components
of the path can be created.
true
if the URL
is valid.public static boolean exists(java.net.URL url)
true
if the specified URL
points to a
resource that currently exists; returns false
otherwise.The default implementation simply returns
false
without doing anything.
public static boolean mkdirs(java.net.URL url)
public static java.lang.String getFileName(java.net.URL url)
URL
, not
including any protocol, hostname authentication, directory path,
anchor, or query. This simply returns the simple filename. For
example, if you pass in an URL
whose string representation
is:
protocol://host:1010/dir1/dir2/file.ext#anchor?query
the returned value is "file.ext
" (without the
quotes).The returned file name should only be used for display purposes and not for opening streams or otherwise trying to locate the resource indicated by the
URL
.
public long getLength(java.net.URL url)
URL
points to. If the length cannot be
determined, -1
is returned.The default implementation attempts to get the content length from the
URLConnection
associated with the URL
. If that
fails for some reason (e.g. the resource does not exist, there was
some other an I/O exception, etc.), -1
is returned.
URLConnection
public static java.lang.String getName(java.net.URL url)
URL
, not
including any protocol, hostname authentication, directory path,
anchor, or query. This simply returns the simple filename. For
example, if you pass in an URL
whose string representation
is:
protocol://host:1010/dir1/dir2/file.ext1.ext2#anchor?query
the returned value is "file
" (without the quotes).The returned file name should only be used for display purposes and not for opening streams or otherwise trying to locate the resource indicated by the
URL
.The default implementation first calls
getFileName(URL)
to
get the file name part. Then all characters starting with the
first occurrence of '.' are removed. The remaining string is then
returned.
public java.lang.String getPath(java.net.URL url)
URL
.
The default implementation delegates to URL.getPath()
.
public java.lang.String getPathNoExt(java.net.URL url)
URL
without the last file
extension. To clarify, the following examples demonstrate the
different cases that come up:
URL |
String |
/dir/file.ext |
/dir/file |
/dir/file.ext1.ext2 |
/dir/file.ext1 |
/dir1.ext1/dir2.ext2/file.ext1.ext2 |
/dir1.ext1/dir2.ext2/file.ext1 |
/file.ext |
/file |
/dir.ext/file |
/dir.ext/file |
/dir/file |
/dir/file |
/file |
/file |
/.ext |
/ |
getPath(URL)
and then trims off all of the characters beginning
with the last "." in the path, if and only if the last "." comes
after the last "/" in the path. If the last "." comes before
the last "/" or if there is no "." at all, then the entire path
is returned.
public java.lang.String getPlatformPathName(java.net.URL url)
URL
; the returned string should be considered acceptable
for users to read. In general, the returned string should omit
as many parts of the URL
as possible. For the "file"
protocol, therefore, the platform pathname should just be the
pathname alone (no protocol) using the appropriate file separator
character for the current platform. For other protocols, it may
be necessary to reformat the URL
string into a more
human-readable form. That decision is left to each
URLFileSystemHelper
implementor.
The default implementation returns url.toString()
.
If the URL
is null
, the empty string is
returned.
URL
in
platform-dependent notation. This value should only be used for
display purposes and not for opening streams or otherwise trying
to locate the document.public static java.net.URL newFileURL(java.io.File file)
public static java.net.URL newFileURL(java.lang.String filePath)
public static java.net.URL newURL(java.lang.String protocol, java.lang.String path)
public static java.net.URL newURL(java.lang.String protocol, java.lang.String userinfo, java.lang.String host, int port, java.lang.String path, java.lang.String query, java.lang.String ref)
URL
whose parts have the exact values that
are specified. In general, you should avoid calling this
method directly.This method is the ultimate place where all of the other
URLFactory
methods end up when creating an
URL
.
Non-sanitizing.
public static final java.io.File url2File(java.net.URL url)
public static java.net.URL getParent(java.net.URL url)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |