public interface Location
Location
is agnostic to the type of file system the resource is on.
Modifier and Type | Field and Description |
---|---|
static String |
TEMP_FILE_SUFFIX
Suffix added to every temp file name generated with
getTempFile(String) . |
Modifier and Type | Method and Description |
---|---|
Location |
append(String child)
Appends the child to the current
Location . |
boolean |
createNew()
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name
does not yet exist.
|
boolean |
createNew(String permission)
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name
does not yet exist.
|
boolean |
delete()
Deletes the file or directory denoted by this abstract pathname.
|
boolean |
delete(boolean recursive)
Deletes the file or directory denoted by this abstract pathname.
|
boolean |
exists()
Checks if the this location exists.
|
String |
getGroup()
Returns the group of the location.
|
InputStream |
getInputStream() |
LocationFactory |
getLocationFactory()
Returns the location factory used to create this instance.
|
String |
getName() |
OutputStream |
getOutputStream() |
OutputStream |
getOutputStream(String permission)
Creates an
OutputStream for this location with the given permission. |
String |
getOwner()
Returns the owner of the location.
|
String |
getPermissions()
Returns the permissions of this
Location . |
Location |
getTempFile(String suffix)
Returns unique location for temporary file to be placed near this location.
|
boolean |
isDirectory()
Checks if this location represents a directory.
|
long |
lastModified() |
long |
length() |
List<Location> |
list()
List the locations under this location.
|
boolean |
mkdirs()
Creates the directory named by this abstract pathname, including any necessary
but nonexistent parent directories.
|
boolean |
mkdirs(String permission)
Creates the directory named by this abstract pathname, including any necessary
but nonexistent parent directories.
|
Location |
renameTo(Location destination)
Moves the file or directory denoted by this abstract pathname.
|
void |
setGroup(String group)
Sets the group of the location.
|
void |
setPermissions(String permission)
Sets the permissions on this location.
|
URI |
toURI() |
static final String TEMP_FILE_SUFFIX
getTempFile(String)
.boolean exists() throws IOException
IOException
String getName()
boolean createNew() throws IOException
true
if the file is successfully create, false
otherwise.IOException
- if error encountered during creation of the fileboolean createNew(String permission) throws IOException
permission
- A permission string. It has to be either a three digit or a nine character string.
For the three digit string, it is similar to the UNIX permission numeric representation.
The first digit is the permission for owner, second digit is the permission for group and
the third digit is the permission for all.
For the nine character string, it uses the format as specified by the
PosixFilePermissions.fromString(String)
method.true
if the file is successfully create, false
otherwise.IOException
- if error encountered during creation of the fileString getPermissions() throws IOException
Location
. The permission string is a nine character string as the format
specified by the PosixFilePermissions.fromString(String)
method.IOException
- if failed to get the permissions of the locationUnsupportedOperationException
- if Posix file permissions are not supported by the local file systemString getOwner() throws IOException
IOException
- if failed to get the owner of the locationString getGroup() throws IOException
IOException
- if failed to get the group of the locationUnsupportedOperationException
- if Posix style groups are not supported by the local file systemvoid setGroup(String group) throws IOException
IOException
- if failed to set the group of the locationUnsupportedOperationException
- if Posix style groups are not supported by the local file systemvoid setPermissions(String permission) throws IOException
permission
- A permission string. See createNew(String)
for the format.IOException
- if failed to set the permissionUnsupportedOperationException
- if Posix file permissions are not supported by the local file systemInputStream getInputStream() throws IOException
InputStream
for this location.IOException
OutputStream getOutputStream() throws IOException
OutputStream
for this location.IOException
OutputStream getOutputStream(String permission) throws IOException
OutputStream
for this location with the given permission. The actual permission supported
depends on implementation.permission
- A permission string. It has to be either a three digit or a nine character string.
For the three digit string, it is similar to the UNIX permission numeric representation.
The first digit is the permission for owner, second digit is the permission for group and
the third digit is the permission for all.
For the nine character string, it uses the format as specified by the
PosixFilePermissions.fromString(String)
method.OutputStream
for writing to this location.IOException
- If failed to create the OutputStream
.Location append(String child) throws IOException
Location
.
Returns a new instance of Location.
child
- to be appended to this location.Location
IOException
Location getTempFile(String suffix) throws IOException
suffix
- part of the file name to include in the temp file nameIOException
boolean delete() throws IOException
IOException
boolean delete(boolean recursive) throws IOException
recursive
is true
, then content of the
directory will be deleted recursively, otherwise the directory must be empty in order to be deleted.
Note that when calling this method with recursive = true
for a directory, any
failure during deletion will have some entries inside the directory being deleted while some are not.recursive
- Indicate if recursively delete a directory. Ignored if the pathname represents a file.IOException
@Nullable Location renameTo(Location destination) throws IOException
destination
- destination locationIOException
boolean mkdirs() throws IOException
IOException
boolean mkdirs(String permission) throws IOException
permission
- A permission string. It has to be either a three digit or a nine character string.
For the three digit string, it is similar to the UNIX permission numeric representation.
The first digit is the permission for owner, second digit is the permission for group and
the third digit is the permission for all.
For the nine character string, it uses the format as specified by the
PosixFilePermissions.fromString(String)
method.IOException
long length() throws IOException
IOException
long lastModified() throws IOException
IOException
boolean isDirectory() throws IOException
true
if it is a directory, false
otherwise.IOException
List<Location> list() throws IOException
IOException
LocationFactory getLocationFactory()
LocationFactory
instance for creating this instance.Copyright © 2013-2016 The Apache Software Foundation. All rights reserved.