public class LocalDataFile extends IFile
IFile
that is in local data
folder. This file's changes are not replicated through the cluster.Constructor and Description |
---|
LocalDataFile(String relativePath)
Creates a new instance with the given relative path.
|
Modifier and Type | Method and Description |
---|---|
protected String |
calculateBasePath()
Returns the base file system path for this file.
|
protected void |
copyRegularFileTo(IFile dest)
Copies this file, assuming it is a regular file, to the specified destination.
|
void |
delete()
Deletes the file or directory.
|
void |
deleteRecursively()
Tries to delete the file or directory recursively.
|
boolean |
exists()
Tests whether the file or directory exists.
|
static LocalDataFile |
fromAbsolutePath(String absolutePath)
Returns a
LocalDataFile resolved from an absolute file path. |
File |
getFile()
Returns the file.
|
InputStream |
getInputStream()
Returns an
InputStream to be used to read this file. |
long |
getLastModified()
Returns the time that the file or directory was last modified.
|
long |
getLength()
Returns the length of the file.
|
OutputStream |
getOutputStream()
Returns an
OutputStream that writes to this file. |
LocalDataFile |
getParent()
Returns the parent
directory . |
LocalDataFile |
getRoot()
Returns the root folder of this file.
|
boolean |
isDirectory()
Tests whether the file is a directory.
|
boolean |
isFile()
Tests whether the file denoted by this
IFile is an actual file. |
IFile[] |
listFiles()
Lists all immediate sub files and directories of this directory (the files and directories whose
IFile.getParent() is equal to this). |
void |
mkdirs()
Creates the directory named by this logical filesystem object, including any necessary but nonexistent parent
directories.
|
byte[] |
readBytes()
Reads this file content in bytes.
|
void |
renameTo(IFile dest2)
Renames the file denoted by this logical filesystem object.
|
LocalDataFile |
resolve(String relativePath)
Resolves the given path against this file.
|
void |
setLastModified(long time)
Sets the last-modified time of the file or directory.
|
ClusterMirroredLocalDataFile |
toClusterMirroredLocalDataFile()
Returns a
ClusterMirroredLocalDataFile with the same relative path of this file. |
URL |
toURL()
Returns a URL that represents this file.
|
void |
write(InputStream inputStream)
Copies the given input stream's content into this file.
|
copyTo, equals, getExtension, getName, getPath, hashCode, isDescendentOf, isEmpty, isRoot, listFiles, readString, readString, relativize, toString, write, write, write, write
public LocalDataFile(String relativePath)
relativePath
- the relative path.public File getFile()
public InputStream getInputStream() throws IOException
IFile
InputStream
to be used to read this file.
If the named file does not exist, is a directory rather than a regular
file, or for some other reason cannot be opened for reading then a
FileNotFoundException
is thrown.
The stream must be closed by the caller of this method. A try-finally statement is recommended to guarantee it is closed.
getInputStream
in interface IInputStreamProvider
FileNotFoundException
- If the named file does not exist, is a directory rather than
a regular file, or for some other reason cannot be opened for
readingIOException
- If an I/O error occurredpublic OutputStream getOutputStream() throws IOException
IFile
OutputStream
that writes to this file.
Any existent content in the file will be discarded and replaced with the content written to this output stream.
The new file content will only be available after OutputStream.close()
is called.
If the file exists but is a directory rather than a regular file, does not exist but cannot be created, the
parent directory does not exist, or cannot be opened for any other reason then a
FileNotFoundException
is thrown. This exception can be thrown in at any time between this call and
the call of OutputStream.close()
.
The stream must be closed by the caller of this method. A try-finally statement is recommended to guarantee it is closed.
FileNotFoundException
- If the file exists but is a directory rather than a regular file, does not exist but cannot be
created, or cannot be opened for any other reasonIOException
- If an I/O error occurredpublic LocalDataFile getParent()
IFile
directory
. If this is already the root of the base
folder
defined in portal file path
, null
is returned. In other words, if
IFile.getPath()
.getRelativePath()
is an empty string, null
is
returned.getParent
in class IFile
directory
PortalFilePath.getParent()
public LocalDataFile getRoot()
IFile
is already the root
, then an equivalent
object will be returned.public LocalDataFile resolve(String relativePath)
IFile
path
must not be an absolute path. In other
words, it cannot begin with a /
.
The path of a file is composed by elements separated by /
. The resolve process consists in create a new
file using this file's relative path concatenated with a /
and the given relative path. If the given
relative path contains an element ..
it means this ..
and the previous element will be eliminated
(for example my/folder/../file.txt
will become my/file.txt
).
resolve
in class IFile
relativePath
- the relative path to be resolved.PortalFilePath.resolve(String)
protected String calculateBasePath()
public static LocalDataFile fromAbsolutePath(String absolutePath)
LocalDataFile
resolved from an absolute file path.absolutePath
- the absolute file pathLocalDataFile
resolved from an absolute file path.IllegalArgumentException
- if the absolute file path couldn't be relativized from local data
folder.public ClusterMirroredLocalDataFile toClusterMirroredLocalDataFile()
ClusterMirroredLocalDataFile
with the same relative path of this file.ClusterMirroredLocalDataFile
with the same relative path of this file.public void delete() throws IOException
IFile
delete
in class IFile
FileCouldNotBeDeletedException
- if this file could not be deletedIOException
- if other error occurpublic void renameTo(IFile dest2) throws FileCouldNotBeRenamedException, FileNotFoundException, IOException
IFile
copyTo(dest);
deleteRecursively();
The rules of this operation follows the rules of IFile.copyTo(IFile)
and IFile.deleteRecursively()
.renameTo
in class IFile
dest2
- The new logical filesystem object for the named fileFileCouldNotBeRenamedException
- if the file could not be renamed for some reasonFileNotFoundException
- if this file doesn't existIOException
- if other error occurpublic void deleteRecursively() throws IOException
IFile
In other words, it is not guaranteed that either all files and directories will be deleted or none of the files and directories will be deleted.
If this file doesn't exist already, no exception will be raised.
deleteRecursively
in class IFile
FileCouldNotBeDeletedException
- if some file or directory couldn't be deletedIOException
- if other error occurpublic void mkdirs() throws IOException
IFile
mkdirs
in class IFile
DirectoryCouldNotBeCreatedException
- if some of the needed directories could not be createdIOException
- if other error occurpublic boolean exists() throws IOException
IFile
exists
in class IFile
true
if and only if the file or directory exists; false
otherwiseIOException
- if some error occur during this operationpublic boolean isDirectory() throws IOException
IFile
isDirectory
in class IFile
true
if and only if the file exists and is a directory; false
otherwiseIOException
- if some error occur during this operationpublic boolean isFile() throws IOException
IFile
IFile
is an actual file. This test might be system-dependent.isFile
in class IFile
true
if and only if the file denoted by this IFile
exists and is an actual
file; false
otherwiseIOException
- if some error occur during this operationpublic void setLastModified(long time) throws IOException
IFile
setLastModified
in class IFile
time
- The new last-modified time, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)FileNotFoundException
- If this file does not existIOException
- if other error occurpublic IFile[] listFiles() throws IOException
IFile
IFile.getParent()
is equal to this).listFiles
in class IFile
FileNotFoundException
- if this file doesn't existFileIsNotDirectoryException
- if this file does not denote a directoryIOException
- if other error occurpublic long getLastModified() throws IOException
IFile
getLastModified
in class IFile
long
value representing the time the file was last modified, measured in milliseconds
since the epoch (00:00:00 GMT, January 1, 1970)FileNotFoundException
- If this file does not existIOException
- if other error occurpublic long getLength() throws IOException
IFile
getLength
in class IFile
NotFileException
- if this is not a fileFileNotFoundException
- If this file does not existIOException
- if other error occurprotected void copyRegularFileTo(IFile dest) throws IOException
IFile
copyRegularFileTo
in class IFile
dest
- the copy destination.IOException
- if I/O error occurred.public void write(InputStream inputStream) throws IOException
IFile
write
in class IFile
inputStream
- the input stream.IOException
public byte[] readBytes() throws IOException
IFile
readBytes
in class IFile
IOException
public URL toURL() throws IOException
IFile
input stream
by implementing URLConnection.getInputStream()
.toURL
in class IFile
IOException
- if some error occur.LumisXP 12.0.0.190809 - Copyright © 2006–2019 Lumis EIP Tecnologia da Informação LTDA. All Rights Reserved.