Class LocalFileSystem


  • @Internal
    public class LocalFileSystem
    extends FileSystem
    The class LocalFileSystem is an implementation of the FileSystem interface for the local file system of the machine where the JVM runs.
    • Constructor Detail

      • LocalFileSystem

        public LocalFileSystem()
        Constructs a new LocalFileSystem object.
    • Method Detail

      • getFileBlockLocations

        public BlockLocation[] getFileBlockLocations​(FileStatus file,
                                                     long start,
                                                     long len)
                                              throws IOException
        Description copied from class: FileSystem
        Return an array containing hostnames, offset and size of portions of the given file. For a nonexistent file or regions, null will be returned. This call is most helpful with DFS, where it returns hostnames of machines that contain the given file. The FileSystem will simply return an elt containing 'localhost'.
        Specified by:
        getFileBlockLocations in class FileSystem
        Throws:
        IOException
      • getUri

        public URI getUri()
        Description copied from class: FileSystem
        Returns a URI whose scheme and authority identify this file system.
        Specified by:
        getUri in class FileSystem
        Returns:
        a URI whose scheme and authority identify this file system
      • getWorkingDirectory

        public Path getWorkingDirectory()
        Description copied from class: FileSystem
        Returns the path of the file system's current working directory.
        Specified by:
        getWorkingDirectory in class FileSystem
        Returns:
        the path of the file system's current working directory
      • getHomeDirectory

        public Path getHomeDirectory()
        Description copied from class: FileSystem
        Returns the path of the user's home directory in this file system.
        Specified by:
        getHomeDirectory in class FileSystem
        Returns:
        the path of the user's home directory in this file system.
      • createRecoverableWriter

        public LocalRecoverableWriter createRecoverableWriter()
                                                       throws IOException
        Description copied from class: FileSystem
        Creates a new RecoverableWriter. A recoverable writer creates streams that can persist and recover their intermediate state. Persisting and recovering intermediate state is a core building block for writing to files that span multiple checkpoints.

        The returned object can act as a shared factory to open and recover multiple streams.

        This method is optional on file systems and various file system implementations may not support this method, throwing an UnsupportedOperationException.

        Overrides:
        createRecoverableWriter in class FileSystem
        Returns:
        A RecoverableWriter for this file system.
        Throws:
        IOException - Thrown, if the recoverable writer cannot be instantiated.
      • listStatus

        public FileStatus[] listStatus​(Path f)
                                throws IOException
        Description copied from class: FileSystem
        List the statuses of the files/directories in the given path if the path is a directory.
        Specified by:
        listStatus in class FileSystem
        Parameters:
        f - given path
        Returns:
        the statuses of the files/directories in the given path
        Throws:
        IOException
      • delete

        public boolean delete​(Path f,
                              boolean recursive)
                       throws IOException
        Description copied from class: FileSystem
        Delete a file.
        Specified by:
        delete in class FileSystem
        Parameters:
        f - the path to delete
        recursive - if path is a directory and set to true, the directory is deleted else throws an exception. In case of a file the recursive can be set to either true or false
        Returns:
        true if delete is successful, false otherwise
        Throws:
        IOException
      • mkdirs

        public boolean mkdirs​(Path f)
                       throws IOException
        Recursively creates the directory specified by the provided path.
        Specified by:
        mkdirs in class FileSystem
        Parameters:
        f - the directory/directories to be created
        Returns:
        trueif the directories either already existed or have been created successfully, false otherwise
        Throws:
        IOException - thrown if an error occurred while creating the directory/directories
      • create

        public FSDataOutputStream create​(Path filePath,
                                         FileSystem.WriteMode overwrite)
                                  throws IOException
        Description copied from class: FileSystem
        Opens an FSDataOutputStream to a new file at the given path.

        If the file already exists, the behavior depends on the given WriteMode. If the mode is set to FileSystem.WriteMode.NO_OVERWRITE, then this method fails with an exception.

        Specified by:
        create in class FileSystem
        Parameters:
        filePath - The file path to write to
        overwrite - The action to take if a file or directory already exists at the given path.
        Returns:
        The stream to the new file at the target path.
        Throws:
        IOException - Thrown, if the stream could not be opened because of an I/O, or because a file already exists at that path and the write mode indicates to not overwrite the file.
      • rename

        public boolean rename​(Path src,
                              Path dst)
                       throws IOException
        Description copied from class: FileSystem
        Renames the file/directory src to dst.
        Specified by:
        rename in class FileSystem
        Parameters:
        src - the file/directory to rename
        dst - the new name of the file/directory
        Returns:
        true if the renaming was successful, false otherwise
        Throws:
        IOException
      • isDistributedFS

        public boolean isDistributedFS()
        Description copied from class: FileSystem
        Returns true if this is a distributed file system. A distributed file system here means that the file system is shared among all Flink processes that participate in a cluster or job and that all these processes can see the same files.
        Specified by:
        isDistributedFS in class FileSystem
        Returns:
        True, if this is a distributed file system, false otherwise.
      • pathToFile

        public File pathToFile​(Path path)
        Converts the given Path to a File for this file system. If the path is empty, we will return new File(".") instead of new File(""), since the latter returns false for isDirectory judgement (See issue https://issues.apache.org/jira/browse/FLINK-18612).
      • getLocalFsURI

        public static URI getLocalFsURI()
        Gets the URI that represents the local file system. That URI is "file:/" on Windows platforms and "file:///" on other UNIX family platforms.
        Returns:
        The URI that represents the local file system.
      • getSharedInstance

        public static LocalFileSystem getSharedInstance()
        Gets the shared instance of this file system.
        Returns:
        The shared instance of this file system.