Package org.apache.flink.core.fs.local
Class LocalFileSystem
- java.lang.Object
-
- org.apache.flink.core.fs.FileSystem
-
- org.apache.flink.core.fs.local.LocalFileSystem
-
@Internal public class LocalFileSystem extends FileSystem
The classLocalFileSystemis an implementation of theFileSysteminterface for the local file system of the machine where the JVM runs.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.flink.core.fs.FileSystem
FileSystem.WriteMode
-
-
Constructor Summary
Constructors Constructor Description LocalFileSystem()Constructs a newLocalFileSystemobject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FSDataOutputStreamcreate(Path filePath, FileSystem.WriteMode overwrite)Opens an FSDataOutputStream to a new file at the given path.LocalRecoverableWritercreateRecoverableWriter()Creates a newRecoverableWriter.booleandelete(Path f, boolean recursive)Delete a file.booleanexists(Path f)Check if exists.BlockLocation[]getFileBlockLocations(FileStatus file, long start, long len)Return an array containing hostnames, offset and size of portions of the given file.FileStatusgetFileStatus(Path f)Return a file status object that represents the path.PathgetHomeDirectory()Returns the path of the user's home directory in this file system.FileSystemKindgetKind()Gets a description of the characteristics of this file system.static URIgetLocalFsURI()Gets the URI that represents the local file system.static LocalFileSystemgetSharedInstance()Gets the shared instance of this file system.URIgetUri()Returns a URI whose scheme and authority identify this file system.PathgetWorkingDirectory()Returns the path of the file system's current working directory.booleanisDistributedFS()Returns true if this is a distributed file system.FileStatus[]listStatus(Path f)List the statuses of the files/directories in the given path if the path is a directory.booleanmkdirs(Path f)Recursively creates the directory specified by the provided path.FSDataInputStreamopen(Path f)Opens an FSDataInputStream at the indicated Path.FSDataInputStreamopen(Path f, int bufferSize)Opens an FSDataInputStream at the indicated Path.FilepathToFile(Path path)Converts the given Path to a File for this file system.booleanrename(Path src, Path dst)Renames the file/directory src to dst.-
Methods inherited from class org.apache.flink.core.fs.FileSystem
create, create, get, getDefaultBlockSize, getDefaultFsUri, getLocalFileSystem, getUnguardedFileSystem, initialize, initialize, initOutPathDistFS, initOutPathLocalFS
-
-
-
-
Method Detail
-
getFileBlockLocations
public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException
Description copied from class:FileSystemReturn 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:
getFileBlockLocationsin classFileSystem- Throws:
IOException
-
getFileStatus
public FileStatus getFileStatus(Path f) throws IOException
Description copied from class:FileSystemReturn a file status object that represents the path.- Specified by:
getFileStatusin classFileSystem- Parameters:
f- The path we want information from- Returns:
- a FileStatus object
- Throws:
FileNotFoundException- when the path does not exist; IOException see specific implementationIOException
-
getUri
public URI getUri()
Description copied from class:FileSystemReturns a URI whose scheme and authority identify this file system.- Specified by:
getUriin classFileSystem- Returns:
- a URI whose scheme and authority identify this file system
-
getWorkingDirectory
public Path getWorkingDirectory()
Description copied from class:FileSystemReturns the path of the file system's current working directory.- Specified by:
getWorkingDirectoryin classFileSystem- Returns:
- the path of the file system's current working directory
-
getHomeDirectory
public Path getHomeDirectory()
Description copied from class:FileSystemReturns the path of the user's home directory in this file system.- Specified by:
getHomeDirectoryin classFileSystem- Returns:
- the path of the user's home directory in this file system.
-
open
public FSDataInputStream open(Path f, int bufferSize) throws IOException
Description copied from class:FileSystemOpens an FSDataInputStream at the indicated Path.- Specified by:
openin classFileSystem- Parameters:
f- the file name to openbufferSize- the size of the buffer to be used.- Throws:
IOException
-
open
public FSDataInputStream open(Path f) throws IOException
Description copied from class:FileSystemOpens an FSDataInputStream at the indicated Path.- Specified by:
openin classFileSystem- Parameters:
f- the file to open- Throws:
IOException
-
createRecoverableWriter
public LocalRecoverableWriter createRecoverableWriter() throws IOException
Description copied from class:FileSystemCreates a newRecoverableWriter. 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:
createRecoverableWriterin classFileSystem- Returns:
- A RecoverableWriter for this file system.
- Throws:
IOException- Thrown, if the recoverable writer cannot be instantiated.
-
exists
public boolean exists(Path f) throws IOException
Description copied from class:FileSystemCheck if exists.- Overrides:
existsin classFileSystem- Parameters:
f- source file- Throws:
IOException
-
listStatus
public FileStatus[] listStatus(Path f) throws IOException
Description copied from class:FileSystemList the statuses of the files/directories in the given path if the path is a directory.- Specified by:
listStatusin classFileSystem- 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:FileSystemDelete a file.- Specified by:
deletein classFileSystem- Parameters:
f- the path to deleterecursive- if path is a directory and set totrue, the directory is deleted else throws an exception. In case of a file the recursive can be set to eithertrueorfalse- Returns:
trueif delete is successful,falseotherwise- Throws:
IOException
-
mkdirs
public boolean mkdirs(Path f) throws IOException
Recursively creates the directory specified by the provided path.- Specified by:
mkdirsin classFileSystem- Parameters:
f- the directory/directories to be created- Returns:
trueif the directories either already existed or have been created successfully,falseotherwise- 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:FileSystemOpens 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 toFileSystem.WriteMode.NO_OVERWRITE, then this method fails with an exception.- Specified by:
createin classFileSystem- Parameters:
filePath- The file path to write tooverwrite- 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:FileSystemRenames the file/directory src to dst.- Specified by:
renamein classFileSystem- Parameters:
src- the file/directory to renamedst- the new name of the file/directory- Returns:
trueif the renaming was successful,falseotherwise- Throws:
IOException
-
isDistributedFS
public boolean isDistributedFS()
Description copied from class:FileSystemReturns 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:
isDistributedFSin classFileSystem- Returns:
- True, if this is a distributed file system, false otherwise.
-
getKind
public FileSystemKind getKind()
Description copied from class:FileSystemGets a description of the characteristics of this file system.- Specified by:
getKindin classFileSystem
-
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.
-
-