@Internal public class LocalFileSystem extends FileSystem
LocalFileSystem
is an implementation of the FileSystem
interface for
the local file system of the machine where the JVM runs.FileSystem.WriteMode
Constructor and Description |
---|
LocalFileSystem()
Constructs a new
LocalFileSystem object. |
Modifier and Type | Method and Description |
---|---|
FSDataOutputStream |
create(Path filePath,
FileSystem.WriteMode overwrite)
Opens an FSDataOutputStream to a new file at the given path.
|
LocalRecoverableWriter |
createRecoverableWriter()
Creates a new
RecoverableWriter . |
boolean |
delete(Path f,
boolean recursive)
Delete a file.
|
boolean |
exists(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.
|
FileStatus |
getFileStatus(Path f)
Return a file status object that represents the path.
|
Path |
getHomeDirectory()
Returns the path of the user's home directory in this file system.
|
FileSystemKind |
getKind()
Gets a description of the characteristics of this file system.
|
static URI |
getLocalFsURI()
Gets the URI that represents the local file system.
|
static LocalFileSystem |
getSharedInstance()
Gets the shared instance of this file system.
|
URI |
getUri()
Returns a URI whose scheme and authority identify this file system.
|
Path |
getWorkingDirectory()
Returns the path of the file system's current working directory.
|
boolean |
isDistributedFS()
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.
|
boolean |
mkdirs(Path f)
Recursively creates the directory specified by the provided path.
|
FSDataInputStream |
open(Path f)
Opens an FSDataInputStream at the indicated Path.
|
FSDataInputStream |
open(Path f,
int bufferSize)
Opens an FSDataInputStream at the indicated Path.
|
File |
pathToFile(Path path)
Converts the given Path to a File for this file system.
|
boolean |
rename(Path src,
Path dst)
Renames the file/directory src to dst.
|
create, create, get, getDefaultBlockSize, getDefaultFsUri, getLocalFileSystem, getUnguardedFileSystem, initialize, initialize, initOutPathDistFS, initOutPathLocalFS
public LocalFileSystem()
LocalFileSystem
object.public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException
FileSystem
getFileBlockLocations
in class FileSystem
IOException
public FileStatus getFileStatus(Path f) throws IOException
FileSystem
getFileStatus
in class FileSystem
f
- The path we want information fromFileNotFoundException
- when the path does not exist; IOException see specific
implementationIOException
public URI getUri()
FileSystem
getUri
in class FileSystem
public Path getWorkingDirectory()
FileSystem
getWorkingDirectory
in class FileSystem
public Path getHomeDirectory()
FileSystem
getHomeDirectory
in class FileSystem
public FSDataInputStream open(Path f, int bufferSize) throws IOException
FileSystem
open
in class FileSystem
f
- the file name to openbufferSize
- the size of the buffer to be used.IOException
public FSDataInputStream open(Path f) throws IOException
FileSystem
open
in class FileSystem
f
- the file to openIOException
public LocalRecoverableWriter createRecoverableWriter() throws IOException
FileSystem
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
.
createRecoverableWriter
in class FileSystem
IOException
- Thrown, if the recoverable writer cannot be instantiated.public boolean exists(Path f) throws IOException
FileSystem
exists
in class FileSystem
f
- source fileIOException
public FileStatus[] listStatus(Path f) throws IOException
FileSystem
listStatus
in class FileSystem
f
- given pathIOException
public boolean delete(Path f, boolean recursive) throws IOException
FileSystem
delete
in class FileSystem
f
- the path to deleterecursive
- 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
true
if delete is successful, false
otherwiseIOException
public boolean mkdirs(Path f) throws IOException
mkdirs
in class FileSystem
f
- the directory/directories to be createdtrue
if the directories either already existed or have been created
successfully, false
otherwiseIOException
- thrown if an error occurred while creating the directory/directoriespublic FSDataOutputStream create(Path filePath, FileSystem.WriteMode overwrite) throws IOException
FileSystem
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.
create
in class FileSystem
filePath
- The file path to write tooverwrite
- The action to take if a file or directory already exists at the given
path.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.public boolean rename(Path src, Path dst) throws IOException
FileSystem
rename
in class FileSystem
src
- the file/directory to renamedst
- the new name of the file/directorytrue
if the renaming was successful, false
otherwiseIOException
public boolean isDistributedFS()
FileSystem
isDistributedFS
in class FileSystem
public FileSystemKind getKind()
FileSystem
getKind
in class FileSystem
public File pathToFile(Path path)
public static URI getLocalFsURI()
"file:/"
on Windows
platforms and "file:///"
on other UNIX family platforms.public static LocalFileSystem getSharedInstance()
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.