Class LocalDataFile

  • All Implemented Interfaces:
    java.io.Serializable, IInputStreamProvider

    public class LocalDataFile
    extends IFile
    Local data file. This is an IFile that is in local data folder. This file's changes are not replicated through the cluster.
    Since:
    8.0.0
    Version:
    $Revision$ $Date$
    See Also:
    Serialized Form
    • Constructor Detail

      • LocalDataFile

        public LocalDataFile​(java.lang.String relativePath)
        Creates a new instance with the given relative path.
        Parameters:
        relativePath - the relative path.
        Since:
        8.0.0
    • Method Detail

      • getFile

        public java.io.File getFile()
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        Description copied from class: IFile
        Returns an 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.

        Specified by:
        getInputStream in interface IInputStreamProvider
        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 reading
        java.io.IOException - If an I/O error occurred
      • getOutputStream

        public java.io.OutputStream getOutputStream()
                                             throws java.io.IOException
        Description copied from class: IFile
        Returns an 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.

        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 reason
        java.io.IOException - If an I/O error occurred
      • getRoot

        public LocalDataFile getRoot()
        Description copied from class: IFile
        Returns the root folder of this file. If this file is already the root, then an equivalent object will be returned.
        Overrides:
        getRoot in class IFile
        Returns:
        the root folder of this file.
      • resolve

        public LocalDataFile resolve​(java.lang.String relativePath)
        Description copied from class: IFile
        Resolves the given path against this file. The 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).

        Overrides:
        resolve in class IFile
        Parameters:
        relativePath - the relative path to be resolved.
        Returns:
        a file relative to this one.
        See Also:
        PortalFilePath.resolve(String)
      • calculateBasePath

        protected java.lang.String calculateBasePath()
        Returns the base file system path for this file.
        Returns:
        the base file system path for this file.
      • fromAbsolutePath

        public static LocalDataFile fromAbsolutePath​(java.lang.String absolutePath)
        Returns a LocalDataFile resolved from an absolute file path.
        Parameters:
        absolutePath - the absolute file path
        Returns:
        a LocalDataFile resolved from an absolute file path.
        Throws:
        java.lang.IllegalArgumentException - if the absolute file path couldn't be relativized from local data folder.
        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.
        Specified by:
        delete in class IFile
        Throws:
        FileCouldNotBeDeletedException - if this file could not be deleted
        java.io.IOException - if other error occur
      • renameTo

        public void renameTo​(IFile dest2)
                      throws FileCouldNotBeRenamedException,
                             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();
        The rules of this operation follows the rules of IFile.copyTo(IFile) and IFile.deleteRecursively().
        Overrides:
        renameTo in class IFile
        Parameters:
        dest2 - The new logical filesystem object for the named file
        Throws:
        FileCouldNotBeRenamedException - if the file could not be renamed for some reason
        java.io.FileNotFoundException - if this file doesn't exist
        java.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.

        Specified by:
        deleteRecursively in class IFile
        Throws:
        FileCouldNotBeDeletedException - if some file or directory couldn't be deleted
        java.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.
        Specified by:
        mkdirs in class IFile
        Throws:
        DirectoryCouldNotBeCreatedException - if some of the needed directories could not be created
        java.io.IOException - if other error occur
      • exists

        public boolean exists()
                       throws java.io.IOException
        Description copied from class: IFile
        Tests whether the file or directory exists.
        Specified by:
        exists in class IFile
        Returns:
        true if and only if the file or directory exists; false otherwise
        Throws:
        java.io.IOException - if some error occur during this operation
      • isDirectory

        public boolean isDirectory()
                            throws java.io.IOException
        Description copied from class: IFile
        Tests whether the file is a directory.
        Specified by:
        isDirectory in class IFile
        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 this IFile is an actual file. This test might be system-dependent.
        Specified by:
        isFile in class IFile
        Returns:
        true if and only if the file denoted by this IFile exists and is an actual file; false otherwise
        Throws:
        java.io.IOException - if some error occur during this operation
      • 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.
        Specified by:
        setLastModified in class IFile
        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 exist
        java.io.IOException - if other error occur
      • 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 whose IFile.getParent() is equal to this).
        Specified by:
        listFiles in class IFile
        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 exist
        FileIsNotDirectoryException - if this file does not denote a directory
        java.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 class IFile
        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 exist
        java.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 class IFile
        Returns:
        The length, in bytes, of the file.
        Throws:
        NotFileException - if this is not a file
        java.io.FileNotFoundException - If this file does not exist
        java.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 class IFile
        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.
        Overrides:
        write in class IFile
        Parameters:
        inputStream - the input stream.
        Throws:
        java.io.IOException
      • readBytes

        public byte[] readBytes()
                         throws java.io.IOException
        Description copied from class: IFile
        Reads this file content in bytes.
        Overrides:
        readBytes in class IFile
        Returns:
        this file content in bytes.
        Throws:
        java.io.IOException
      • 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's input stream by implementing URLConnection.getInputStream().
        Specified by:
        toURL in class IFile
        Returns:
        a URL that represents this file.
        Throws:
        java.io.IOException - if some error occur.