|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.springsource.util.io.PathReference
public final class PathReference
Represents a reference, by path, to a location on the file system. This location may be a file or a directory, or it may point to a non-existent location.
Concurrent Semantics
Nested Class Summary | |
---|---|
static interface |
PathReference.PathFilter
Allows filtering during PathReference operations. |
Field Summary | |
---|---|
private java.io.File |
file
The File handle that backs this reference. |
Constructor Summary | |
---|---|
PathReference(java.io.File file)
Creates a new PathReference for the supplied File . |
|
PathReference(java.lang.String path)
Creates a new PathReference for the supplied path. |
|
PathReference(java.net.URI uri)
Creates a new PathReference for the supplied URI which must point to a file location. |
Method Summary | |
---|---|
static PathReference |
concat(java.lang.String... parts)
Creates a new PathReference by concatenating the supplied parts , treating each
part as a separate path element. |
PathReference |
copy(PathReference dest)
Same as calling copy(to, false) . |
PathReference |
copy(PathReference dest,
boolean recursive)
Same as calling copy(to, recursive, null) ; |
PathReference |
copy(PathReference dest,
boolean recursive,
PathReference.PathFilter filter)
Copies the contents of the file/directory to location referenced supplied PathReference . |
private static void |
copyFile(java.io.File src,
java.io.File dest)
Copies src to dest . |
PathReference |
createDirectory()
Creates a directory at the location of this PathReference . |
PathReference |
createFile()
Creates a new file at the location of this PathReference . |
boolean |
delete()
Delete the file/directory referenced by this PathReference . |
boolean |
delete(boolean recursive)
Delete the file/directory referenced by this PathReference . |
boolean |
equals(java.lang.Object that)
|
boolean |
exists()
Queries whether or not this PathReference points to a vaild file or directory. |
java.lang.String |
fileContents()
Gets the contents of the File pointed to by this PathReference . |
java.lang.String |
getAbsolutePath()
Gets the absolute path of this PathReference . |
java.lang.String |
getCanonicalPath()
Gets the canonical path of this PathReference . |
java.lang.String |
getName()
Gets the name of the file or directory referenced by this PathReference . |
PathReference |
getParent()
Gets the parent directory of this PathReference . |
int |
hashCode()
|
boolean |
isAbsolute()
Queries whether or not the path of this PathReference is absolute. |
boolean |
isDirectory()
Queries whether or not this PathReference points to a directory. |
boolean |
isFile()
Queries whether or not this PathReference points to a file. |
PathReference |
newChild(java.lang.String name)
Creates a new PathReference by concatenating the path of this PathReference with
the supplied name . |
private static void |
recursiveCopy(java.io.File src,
java.io.File dest,
PathReference.PathFilter filter)
Recursively copy the contents of src to dest . |
PathReference |
toAbsoluteReference()
Creates a PathReference that points to the absolute location of this PathReference . |
PathReference |
toCanonicalReference()
Creates a PathReference that points to the canonical location of this PathReference . |
java.io.File |
toFile()
Converts this PathReference to a File . |
java.lang.String |
toString()
|
boolean |
touch()
Set the last modified time of the File pointed to by this PathReference to the current time. |
java.net.URI |
toURI()
Converts this PathReference into a URI . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final java.io.File file
File
handle that backs this reference.
Constructor Detail |
---|
public PathReference(java.lang.String path)
PathReference
for the supplied path.
path
- the path to reference.public PathReference(java.net.URI uri)
PathReference
for the supplied URI
which must point to a file location.
uri
- the file URI to referencepublic PathReference(java.io.File file)
PathReference
for the supplied File
.
file
- the file to reference.Method Detail |
---|
public java.io.File toFile()
PathReference
to a File
.
File
.public boolean exists()
PathReference
points to a vaild file or directory.
true
if the location is valid, otherwise false
.public boolean isFile()
PathReference
points to a file.
true
if this location points to a file, otherwise false
.public boolean isDirectory()
PathReference
points to a directory.
true
if this location points to a directory, otherwise false
.public java.lang.String getName()
PathReference
.
File.getName()
public PathReference getParent()
PathReference
.
File.getParentFile()
public boolean isAbsolute()
PathReference
is absolute.
true
if the path is absolute, otherwise false
.public java.lang.String getAbsolutePath()
PathReference
.
public java.net.URI toURI()
PathReference
into a URI
.
PathReference
.File.toURI()
public java.lang.String getCanonicalPath()
PathReference
.
public PathReference toAbsoluteReference()
PathReference
that points to the absolute location of this PathReference
.
PathReference
.public PathReference toCanonicalReference()
PathReference
that points to the canonical location of this PathReference
.
PathReference
.public java.lang.String toString()
toString
in class java.lang.Object
public boolean delete()
PathReference
. Has the same effect as calling
delete(false)
.
true
if the file is deleted, otherwise false
.public boolean delete(boolean recursive)
PathReference
. Nested contents can optionally be
deleted by passing recursive = true
. Non-recursive deletes will fail (return false
for non-empty directories).
recursive
- should the delete process nested contents recursively.
true
if the file is deleted, otherwise false
.public PathReference copy(PathReference dest)
copy(to, false)
.
dest
- the destination to copy to.
PathReference
.public PathReference copy(PathReference dest, boolean recursive)
copy(to, recursive, null)
;
dest
- the destination to copy to.recursive
- whether the copy should be recursive or not.
PathReference
.public PathReference copy(PathReference dest, boolean recursive, PathReference.PathFilter filter)
PathReference
. The
exact semantics of the copy depend on the state of both the source and destination locations.
When copying a file, if the destination location already exists and is a file then a FatalIOException
is
thrown. If the destination location exists and is a directory, the file is copied into this directory with the
same name
as the source location. If the destination location does not exist, then the file is
copied to this location directly.
When copying a directory, if the destination location exists then the directory is copied into the already
existing directory with the same name as the source location. If the destination location does not exist, then
the directory is copied directly to the destination location and thus gets the name defined by the destination
location.
A PathReference.PathFilter
can be used to specify exactly which files will be included in the copy. Passing
null
for the filter includes all files.
Non-recursive copies on non-empty directories will fail with FatalIOException
.
dest
- the destination to copy to.recursive
- whether the copy should be recursive or not.filter
- a PathFilter
controlling which files are included in the copy.
PathReference
.public PathReference newChild(java.lang.String name)
PathReference
by concatenating the path of this PathReference
with
the supplied name
. Note that this method does not create a physical file or
directory at the child location.
name
- the name of the new child entry.
PathReference
.public PathReference createFile()
PathReference
.
PathReference
for chaining purposes.public PathReference createDirectory()
PathReference
.
PathReference
for chaining purposes.public static PathReference concat(java.lang.String... parts)
PathReference
by concatenating the supplied parts
, treating each
part as a separate path element.
parts
- the path elements.
PathReference
for the concatenated path.private static void recursiveCopy(java.io.File src, java.io.File dest, PathReference.PathFilter filter)
src
to dest
.
src
- the source file.dest
- the destination file.private static void copyFile(java.io.File src, java.io.File dest)
src
to dest
.
src
- the source File
.dest
- the destination File
.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object that)
equals
in class java.lang.Object
public java.lang.String fileContents() throws java.io.IOException
File
pointed to by this PathReference
.
String
.
java.io.IOException
- if the file cannot be found or read.public boolean touch()
File
pointed to by this PathReference
to the current time.
Note: the behaviour is not the same as UNIX(TM) touch as the latter also sets the file access time.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |