Class ClusterMirroredLocalDataFile
- java.lang.Object
-
- lumis.portal.filesystem.IFile
-
- lumis.portal.filesystem.impl.ClusterMirroredLocalDataFile
-
- All Implemented Interfaces:
java.io.Serializable
,IInputStreamProvider
public class ClusterMirroredLocalDataFile extends IFile
A local data file that has its changes replicated over the cluster.- Since:
- 8.0.0
- Version:
- $Revision: 22716 $ $Date: 2019-05-06 17:16:41 -0300 (Mon, 06 May 2019) $
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ClusterMirroredLocalDataFile(java.lang.String relativePath)
Creates a new instance for the given relative path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.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
copyTo(IFile dest)
Copies the file denoted by this logical filesystem object.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.java.io.File
getFile()
java.io.InputStream
getInputStream()
Returns anInputStream
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.java.io.OutputStream
getOutputStream()
Returns anOutputStream
that writes to this file.ClusterMirroredLocalDataFile
getParent()
Returns the parentdirectory
.ClusterMirroredLocalDataFile
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 thisIFile
is an actual file.IFile[]
listFiles()
Lists all immediate sub files and directories of this directory (the files and directories whoseIFile.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 dest)
Renames the file denoted by this logical filesystem object.ClusterMirroredLocalDataFile
resolve(java.lang.String relativePath)
Resolves the given path against this file.void
setLastModified(long time)
Sets the last-modified time of the file or directory.LocalDataFile
toLocalDataFile()
Returns aLocalDataFile
of the same relative path of this file.java.net.URL
toURL()
Returns a URL that represents this file.void
write(java.io.InputStream inputStream)
Copies the given input stream's content into this file.-
Methods inherited from class lumis.portal.filesystem.IFile
equals, getExtension, getName, getPath, hashCode, isDescendentOf, isEmpty, isRoot, listFiles, readString, readString, relativize, toString, write, write, write, write
-
-
-
-
Method Detail
-
calculateBasePath
protected java.lang.String calculateBasePath()
Returns the base file system path for this file.- Returns:
- the base file system path for this file.
-
getFile
public java.io.File getFile()
-
getParent
public ClusterMirroredLocalDataFile getParent()
Description copied from class:IFile
Returns the parentdirectory
. If this is already the root of thebase folder
defined inportal file path
,null
is returned. In other words, ifIFile.getPath()
.getRelativePath()
is an empty string,null
is returned.- Overrides:
getParent
in classIFile
- Returns:
- the parent
directory
- See Also:
PortalFilePath.getParent()
-
getRoot
public ClusterMirroredLocalDataFile getRoot()
Description copied from class:IFile
Returns the root folder of this file. If this fileis already the root
, then an equivalent object will be returned.
-
resolve
public ClusterMirroredLocalDataFile resolve(java.lang.String relativePath)
Description copied from class:IFile
Resolves the given path against this file. Thepath
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 examplemy/folder/../file.txt
will becomemy/file.txt
).- Overrides:
resolve
in classIFile
- Parameters:
relativePath
- the relative path to be resolved.- Returns:
- a file relative to this one.
- See Also:
PortalFilePath.resolve(String)
-
toLocalDataFile
public LocalDataFile toLocalDataFile()
Returns aLocalDataFile
of the same relative path of this file.- Returns:
- a
LocalDataFile
of the same relative path of this file. - Since:
- 8.0.0
-
delete
public void delete() throws java.io.IOException
Description copied from class:IFile
Deletes the file or directory. If this denotes a directory, then the directory must be empty in order to be deleted. If this file doesn't exist already, no exception will be raised.- Throws:
FileCouldNotBeDeletedException
- if this file could not be deletedjava.io.IOException
- if other error occur
-
deleteRecursively
public void deleteRecursively() throws java.io.IOException
Description copied from class:IFile
Tries to delete the file or directory recursively. If the deletion of some file or directory fails the deletion will not be complete, but some files and/or directories might already have been deleted.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.
- Throws:
FileCouldNotBeDeletedException
- if some file or directory couldn't be deletedjava.io.IOException
- if other error occur
-
mkdirs
public void mkdirs() throws java.io.IOException
Description copied from class:IFile
Creates the directory named by this logical filesystem object, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.- Throws:
DirectoryCouldNotBeCreatedException
- if some of the needed directories could not be createdjava.io.IOException
- if other error occur
-
renameTo
public void renameTo(IFile dest) throws FileCouldNotBeRenamedException, FileAlreadyExistsException, java.io.FileNotFoundException, java.io.IOException
Description copied from class:IFile
Renames the file denoted by this logical filesystem object. This operation is equivalent to:copyTo(dest);
deleteRecursively();IFile.copyTo(IFile)
andIFile.deleteRecursively()
.- Parameters:
dest
- The new logical filesystem object for the named file- Throws:
FileCouldNotBeRenamedException
- if the file could not be renamed for some reasonjava.io.FileNotFoundException
- if this file doesn't existjava.io.IOException
- if other error occurFileAlreadyExistsException
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Description copied from class:IFile
Returns anInputStream
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.
- Specified by:
getInputStream
in interfaceIInputStreamProvider
- Returns:
- an InputStream to be used to read this file.
- Throws:
java.io.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 readingjava.io.IOException
- If an I/O error occurred
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOException
Description copied from class:IFile
Returns anOutputStream
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 ofOutputStream.close()
.The stream must be closed by the caller of this method. A try-finally statement is recommended to guarantee it is closed.
- Returns:
- an OutputStream to be used to write this file.
- Throws:
java.io.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 reasonjava.io.IOException
- If an I/O error occurred
-
setLastModified
public void setLastModified(long time) throws java.io.IOException
Description copied from class:IFile
Sets the last-modified time of the file or directory.- Parameters:
time
- The new last-modified time, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)- Throws:
java.io.FileNotFoundException
- If this file does not existjava.io.IOException
- if other error occur
-
copyTo
public void copyTo(IFile dest) throws java.io.IOException
Description copied from class:IFile
Copies the file denoted by this logical filesystem object.This operation will copy this file or directory to the target file or directory using the following criteria:
- If this file does not exist, a
FileNotFoundException
will be raised. - If this file is a regular file:
- If the target file does not exist, the target file will be created using this file's content.
- If the target file is an already existent regular file, the target's content will be replaced by this file's content.
- If the target file is not a regular file, a
FileNotFoundException
will be raised.
- If this file is a directory:
- If the target file does not exist, the target file will be created as a directory and this file's children will be copied recursively.
- If the target file is a directory, this file's children will be copied recursively. Those files that already existed in the target but does not exist in this file will not be removed.
- If the target file exists and is not a directory, a
FileNotFoundException
will be raised.
- If this file exists but it isn't neither a regular file nor a directory, a
FileNotFoundException
will be raised.
- Overrides:
copyTo
in classIFile
- Parameters:
dest
- The new logical filesystem object for the named file- Throws:
java.io.FileNotFoundException
- if this file doesn't existFileCouldNotBeCopiedException
- if some error occur during copyjava.io.IOException
- if other error occur
- If this file does not exist, a
-
exists
public boolean exists() throws java.io.IOException
Description copied from class:IFile
Tests whether the file or directory exists.
-
isDirectory
public boolean isDirectory() throws java.io.IOException
Description copied from class:IFile
Tests whether the file is a directory.- Specified by:
isDirectory
in classIFile
- Returns:
true
if and only if the file exists and is a directory;false
otherwise- Throws:
java.io.IOException
- if some error occur during this operation
-
isFile
public boolean isFile() throws java.io.IOException
Description copied from class:IFile
Tests whether the file denoted by thisIFile
is an actual file. This test might be system-dependent.
-
listFiles
public IFile[] listFiles() throws java.io.IOException
Description copied from class:IFile
Lists all immediate sub files and directories of this directory (the files and directories whoseIFile.getParent()
is equal to this).- Specified by:
listFiles
in classIFile
- Returns:
- all immediate sub files and directories of this directory; an empty list if this directory has no files and no directories.
- Throws:
java.io.FileNotFoundException
- if this file doesn't existFileIsNotDirectoryException
- if this file does not denote a directoryjava.io.IOException
- if other error occur
-
getLastModified
public long getLastModified() throws java.io.IOException
Description copied from class:IFile
Returns the time that the file or directory was last modified.- Specified by:
getLastModified
in classIFile
- Returns:
- A
long
value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970) - Throws:
java.io.FileNotFoundException
- If this file does not existjava.io.IOException
- if other error occur
-
getLength
public long getLength() throws java.io.IOException
Description copied from class:IFile
Returns the length of the file.- Specified by:
getLength
in classIFile
- Returns:
- The length, in bytes, of the file.
- Throws:
NotFileException
- if this is not a filejava.io.FileNotFoundException
- If this file does not existjava.io.IOException
- if other error occur
-
copyRegularFileTo
protected void copyRegularFileTo(IFile dest) throws java.io.IOException
Description copied from class:IFile
Copies this file, assuming it is a regular file, to the specified destination.- Overrides:
copyRegularFileTo
in classIFile
- Parameters:
dest
- the copy destination.- Throws:
java.io.IOException
- if I/O error occurred.
-
write
public void write(java.io.InputStream inputStream) throws java.io.IOException
Description copied from class:IFile
Copies the given input stream's content into this file.
-
readBytes
public byte[] readBytes() throws java.io.IOException
Description copied from class:IFile
Reads this file content in bytes.
-
toURL
public java.net.URL toURL() throws java.io.IOException
Description copied from class:IFile
Returns a URL that represents this file. The URL must, at least, provide means of accessing this file'sinput stream
by implementingURLConnection.getInputStream()
.
-
-