@StableMinor(version="12.3", sinceVersion="8.0") public abstract class IFile extends Object implements Serializable, IInputStreamProvider
It uses a PortalFilePath
to normalize the file or directory among the
cluster servers and exposes the supported file and directory operations. Once
created, its PortalFilePath
is immutable. The PortalFilePath
also is used to check whether this IFile
is equal to another (see
equals(Object)
).
In some implementations the changes made in one cluster server might take a while to be reflected in the other servers.
Implementations must raise the appropriate filesystem events as file systems changes are performed using this API.
Implementations must guarantee the read/write file integrity. The following must be guaranteed (even in highly concurrent scenarios):
read operation
must be able to
read the entire file content without garbling with simultaneous writeswrite operation
must be able to
write the entire file content without garbling with simultaneous writes
Any changes must take effect immediately, so that if the value is read
immediately after the change operation, the returned value is the one that
has been set, once the commands are called in the same cluster server.
However, the same functionality is not guarantee if the change operation and
the read operation are called in different cluster servers.
But if a file operation is performed through a cluster transmission
with a total order
flag set,
this file operation (in any server) must happen after any file
operation performed before the transmission was sent in the cluster server
that sent the transmission.
lumis.portal.filesystem
,
lumis.portal.filesystem.event
,
IFileSystem
,
IFileSystemManager.getFile(PortalFilePath)
,
Serialized FormConstructor and Description |
---|
IFile(PortalFilePath portalFilePath)
Creates a new instance with the given PortalFilePath.
|
Modifier and Type | Method and Description |
---|---|
protected void |
copyRegularFileTo(IFile dest)
Copies this file, assuming it is a regular file, to the specified destination.
|
void |
copyTo(IFile dest)
Copies the file denoted by this logical filesystem object.
|
abstract void |
delete()
Deletes the file or directory.
|
abstract void |
deleteRecursively()
Tries to delete the file or directory recursively.
|
boolean |
equals(Object obj)
Makes use of
PortalFilePath to check if this object represents
the same file system logical object represented by the given object. |
abstract boolean |
exists()
Tests whether the file or directory exists.
|
String |
getExtension()
Returns this file's extension or
null if this file doesn't have an extension. |
abstract InputStream |
getInputStream()
Returns an
InputStream to be used to read this file. |
abstract long |
getLastModified()
Returns the time that the file or directory was last modified.
|
abstract long |
getLength()
Returns the length of the file.
|
String |
getName()
Returns the name of the file or directory.
|
abstract OutputStream |
getOutputStream()
Returns an
OutputStream that writes to this file. |
IFile |
getParent()
Returns the parent
directory . |
PortalFilePath |
getPath()
Returns the
PortalFilePath that represents this file or
directory. |
IFile |
getRoot()
Returns the root folder of this file.
|
int |
hashCode()
Makes use of
PortalFilePath to calculate this hashcode. |
boolean |
isDescendentOf(IFile file)
Returns whether this file is descendent of the given file.
|
abstract boolean |
isDirectory()
Tests whether the file is a directory.
|
boolean |
isEmpty()
Returns whether this directory is empty.
|
abstract boolean |
isFile()
Tests whether the file denoted by this
IFile is an actual file. |
boolean |
isRoot()
Returns whether this file is the root of its base folder.
|
abstract IFile[] |
listFiles()
Lists all immediate sub files and directories of this directory (the files and directories whose
getParent() is equal to this). |
IFile[] |
listFiles(IFileFilter fileFilter)
Lists all immediate sub files and directories of this directory (the files and directories whose
getParent() is equal to this), respecting a given file filter . |
abstract 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.
|
String |
readString()
Reads this file using the
UTF-8 encoding. |
String |
readString(String charset)
Reads this file using the given charset name.
|
String |
relativize(IFile other)
Relativizes the given file against this file.
|
void |
renameTo(IFile dest)
Renames the file denoted by this logical filesystem object.
|
IFile |
resolve(String relativePath)
Resolves the given path against this file.
|
abstract void |
setLastModified(long time)
Sets the last-modified time of the file or directory.
|
String |
toString() |
abstract URL |
toURL()
Returns a URL that represents this file.
|
void |
write(byte[] buf)
Writes the given bytes in this file.
|
void |
write(File file)
Writes the contents of the given file into this file.
|
void |
write(InputStream inputStream)
Copies the given input stream's content into this file.
|
void |
write(String str)
Writes the given string in this file using
UTF-8 encoding. |
void |
write(String str,
String charset)
Writes the given string in this file using the given charset name.
|
public IFile(PortalFilePath portalFilePath)
portalFilePath
- the portal file path.public final String getName()
PortalFilePath.getRelativePath()
), then the empty string is returned.PortalFilePath.getName()
public IFile getParent()
directory
. If this is already the root of the base
folder
defined in portal file path
, null
is returned. In other words, if
getPath()
.getRelativePath()
is an empty string, null
is
returned.directory
PortalFilePath.getParent()
public IFile resolve(String relativePath)
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
).
relativePath
- the relative path to be resolved.IllegalArgumentException
- if path
is null
or it starts with a /
.PortalFilePath.resolve(String)
public final boolean isRoot()
public final boolean isDescendentOf(IFile file)
file
- the file to be tested.public final String relativize(IFile other)
null
if the given file
couldn't be relativized. The given file can only be relativized against this one if it
is descendent of this file
.other
- the file to be relativized.null
if it couldn't be relativized.PortalFilePath.relativize(PortalFilePath)
public IFile getRoot()
is already the root
, then an equivalent
object will be returned.public final boolean isEmpty() throws FileNotFoundException, FileIsNotDirectoryException, IOException
FileNotFoundException
- if this file does not exist.FileIsNotDirectoryException
- if this file does not denote a directory.IOException
- if other error occur.public final PortalFilePath getPath()
PortalFilePath
that represents this file or
directory. This method never returns null
.PortalFilePath
that represents this file or directorypublic final String getExtension() throws IOException
null
if this file doesn't have an extension. The extension is the
remaining part of file name
after the last .
character.IOException
- if some error occur.public final int hashCode()
PortalFilePath
to calculate this hashcode. Indeed,
they are exactly the same.public final boolean equals(Object obj)
PortalFilePath
to check if this object represents
the same file system logical object represented by the given object.
Indeed, the following is always true for two (not null
) given
IFile
— file1 and file2:
and also:file1.equals(file2)
if and only iffile1.getPath().equals(file2.getPath())
iffile1.getPath().equals(file2.getPath())
istrue
thenfile1.equals(file2)
is alsotrue
public abstract boolean exists() throws IOException
true
if and only if the file or directory exists; false
otherwiseIOException
- if some error occur during this operationpublic abstract boolean isDirectory() throws IOException
true
if and only if the file exists and is a directory; false
otherwiseIOException
- if some error occur during this operationpublic abstract boolean isFile() throws IOException
IFile
is an actual file. This test might be system-dependent.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 abstract void setLastModified(long time) throws FileNotFoundException, IOException
time
- The new last-modified time, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)IllegalArgumentException
- If the argument is negativeFileNotFoundException
- If this file does not existIOException
- if other error occurpublic abstract long getLastModified() throws FileNotFoundException, IOException
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 abstract long getLength() throws FileNotFoundException, NotFileException, IOException
NotFileException
- if this is not a fileFileNotFoundException
- If this file does not existIOException
- if other error occurpublic abstract void delete() throws FileCouldNotBeDeletedException, IOException
FileCouldNotBeDeletedException
- if this file could not be deletedIOException
- if other error occurpublic abstract void deleteRecursively() throws FileCouldNotBeDeletedException, IOException
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.
FileCouldNotBeDeletedException
- if some file or directory couldn't be deletedIOException
- if other error occurpublic abstract IFile[] listFiles() throws FileNotFoundException, FileIsNotDirectoryException, IOException
getParent()
is equal to this).FileNotFoundException
- if this file doesn't existFileIsNotDirectoryException
- if this file does not denote a directoryIOException
- if other error occurpublic IFile[] listFiles(IFileFilter fileFilter) throws FileNotFoundException, FileIsNotDirectoryException, IOException
getParent()
is equal to this), respecting a given file filter
.fileFilter
- the file filter to be applied when searching sub filesFileNotFoundException
- if this file doesn't existFileIsNotDirectoryException
- if this file does not denote a directoryIOException
- if other error occurpublic abstract void mkdirs() throws DirectoryCouldNotBeCreatedException, IOException
DirectoryCouldNotBeCreatedException
- if some of the needed directories could not be createdIOException
- if other error occurpublic void renameTo(IFile dest) throws FileCouldNotBeRenamedException, FileNotFoundException, IOException
copyTo(dest);
deleteRecursively();
The rules of this operation follows the rules of copyTo(IFile)
and deleteRecursively()
.dest
- The new logical filesystem object for the named fileIllegalArgumentException
- if dest
is null
FileNotFoundException
- if this file doesn't existFileCouldNotBeRenamedException
- if the file could not be renamed for some reasonIOException
- if other error occurpublic void copyTo(IFile dest) throws FileNotFoundException, FileCouldNotBeCopiedException, IOException
This operation will copy this file or directory to the target file or directory using the following criteria:
FileNotFoundException
will be raised.FileNotFoundException
will be raised.FileNotFoundException
will be raised.FileNotFoundException
will
be raised.dest
- The new logical filesystem object for the named fileFileNotFoundException
- if this file doesn't existFileCouldNotBeCopiedException
- if some error occur during copyIOException
- if other error occurprotected void copyRegularFileTo(IFile dest) throws IOException
dest
- the copy destination.IOException
- if I/O error occurred.public abstract InputStream getInputStream() throws IOException
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 abstract OutputStream getOutputStream() throws IOException
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 final String readString() throws IOException
UTF-8
encoding.IOException
public final String readString(String charset) throws IOException
charset
- the charset nameIOException
public byte[] readBytes() throws IOException
IOException
public final void write(byte[] buf) throws IOException
buf
- the bytes to be written.IOException
public final void write(String str, String charset) throws IOException
str
- the string to be written.charset
- the charset nameIOException
public final void write(String str) throws IOException
UTF-8
encoding.str
- the string to be written.IOException
public void write(InputStream inputStream) throws IOException
inputStream
- the input stream.IOException
public final void write(File file) throws IOException
file
- the file with the desired contents.IOException
- if some error occur.public abstract URL toURL() throws IOException
input stream
by implementing URLConnection.getInputStream()
.IOException
- if some error occur.LumisXP 12.3.0.200408 - Copyright © 2006–2020 Lumis EIP Tecnologia da Informação LTDA. All Rights Reserved.