Package org.apache.hadoop.fs
Class FileContext.Util
java.lang.Object
org.apache.hadoop.fs.FileContext.Util
- Enclosing class:
- FileContext
Utility/library methods built over the basic FileContext methods.
Since this are library functions, the oprtation are not atomic
and some of them may partially complete if other threads are making
changes to the same part of the name space.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCopy file from src to dest.booleanCopy from src to dst, optionally deleting src and overwriting dst.booleanDoes the file exist?Return theContentSummaryof path f.globStatus(Path pathPattern) Return all the files that match filePattern and are not checksum files.globStatus(Path pathPattern, PathFilter filter) Return an array of FileStatus objects whose path names match pathPattern and is accepted by the user-supplied path filter.List the statuses and block locations of the files in the given path.listStatus(Path f) List the statuses of the files/directories in the given path if the path is a directory.listStatus(Path[] files) listStatus(Path[] files, PathFilter filter) Filter files/directories in the given list of paths using user-supplied path filter.listStatus(Path f, PathFilter filter) Filter files/directories in the given path using the user-supplied path filter.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
exists
public boolean exists(Path f) throws AccessControlException, UnsupportedFileSystemException, IOException Does the file exist? Note: Avoid using this method if you already have FileStatus in hand. Instead reuse the FileStatus- Parameters:
f- the file or dir to be checked- Returns:
- if f exists true, not false.
- Throws:
AccessControlException- If access is deniedIOException- If an I/O error occurredUnsupportedFileSystemException- If file system forfis not supported Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server
-
getContentSummary
public ContentSummary getContentSummary(Path f) throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException Return theContentSummaryof path f.- Parameters:
f- path- Returns:
- the
ContentSummaryof path f. - Throws:
AccessControlException- If access is deniedFileNotFoundException- Iffdoes not existUnsupportedFileSystemException- If file system forfis not supportedIOException- If an I/O error occurred Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server
-
listStatus
public FileStatus[] listStatus(Path[] files) throws AccessControlException, FileNotFoundException, IOException - Parameters:
files- files.- Returns:
- file status array.
- Throws:
AccessControlException- If access is denied.FileNotFoundException- Iffilesdoes not exist.IOException- If an I/O error occurred.
-
listStatus
public FileStatus[] listStatus(Path f, PathFilter filter) throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException Filter files/directories in the given path using the user-supplied path filter.- Parameters:
f- is the path namefilter- is the user-supplied path filter- Returns:
- an array of FileStatus objects for the files under the given path after applying the filter
- Throws:
AccessControlException- If access is deniedFileNotFoundException- Iffdoes not existUnsupportedFileSystemException- If file system forpathPatternis not supportedIOException- If an I/O error occurred Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server
-
listStatus
public FileStatus[] listStatus(Path[] files, PathFilter filter) throws AccessControlException, FileNotFoundException, IOException Filter files/directories in the given list of paths using user-supplied path filter.- Parameters:
files- is a list of pathsfilter- is the filter- Returns:
- a list of statuses for the files under the given paths after applying the filter
- Throws:
AccessControlException- If access is deniedFileNotFoundException- If a file infilesdoes not existIOException- If an I/O error occurred Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server
-
listStatus
public FileStatus[] listStatus(Path f) throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException List the statuses of the files/directories in the given path if the path is a directory.- Parameters:
f- is the path- Returns:
- an array that contains statuses of the files/directories in the given path
- Throws:
AccessControlException- If access is deniedFileNotFoundException- Iffdoes not existUnsupportedFileSystemException- If file system forfis not supportedIOException- If an I/O error occurred Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server
-
listFiles
public RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive) throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException List the statuses and block locations of the files in the given path. If the path is a directory, if recursive is false, returns files in the directory; if recursive is true, return files in the subtree rooted at the path. The subtree is traversed in the depth-first order. If the path is a file, return the file's status and block locations. Files across symbolic links are also returned.- Parameters:
f- is the pathrecursive- if the subdirectories need to be traversed recursively- Returns:
- an iterator that traverses statuses of the files If any IO exception (for example a sub-directory gets deleted while listing is being executed), next() or hasNext() of the returned iterator may throw a RuntimeException with the IO exception as the cause.
- Throws:
AccessControlException- If access is deniedFileNotFoundException- Iffdoes not existUnsupportedFileSystemException- If file system forfis not supportedIOException- If an I/O error occurred Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server
-
globStatus
public FileStatus[] globStatus(Path pathPattern) throws AccessControlException, UnsupportedFileSystemException, IOException Return all the files that match filePattern and are not checksum files. Results are sorted by their names.
A filename pattern is composed of regular characters and special pattern matching characters, which are:
-
-
? - Matches any single character.
-
* - Matches zero or more characters.
-
[abc] - Matches a single character from character set
{a,b,c}. -
[a-b] - Matches a single character from the character range
{a...b}. Note: characteramust be lexicographically less than or equal to characterb. -
[^a] - Matches a single char that is not from character set or range
{a}. Note that the^character must occur immediately to the right of the opening bracket. -
\c - Removes (escapes) any special meaning of character c.
-
{ab,cd} - Matches a string from the string set
{ab, cd} -
{ab,c{de,fh}} - Matches a string from string set
{ab, cde, cfh}
-
- Parameters:
pathPattern- a glob specifying a path pattern- Returns:
- an array of paths that match the path pattern
- Throws:
AccessControlException- If access is deniedUnsupportedFileSystemException- If file system forpathPatternis not supportedIOException- If an I/O error occurred Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server
-
-
globStatus
public FileStatus[] globStatus(Path pathPattern, PathFilter filter) throws AccessControlException, UnsupportedFileSystemException, IOException Return an array of FileStatus objects whose path names match pathPattern and is accepted by the user-supplied path filter. Results are sorted by their path names. Return null if pathPattern has no glob and the path does not exist. Return an empty array if pathPattern has a glob and no path matches it.- Parameters:
pathPattern- glob specifying the path patternfilter- user-supplied path filter- Returns:
- an array of FileStatus objects
- Throws:
AccessControlException- If access is deniedUnsupportedFileSystemException- If file system forpathPatternis not supportedIOException- If an I/O error occurred Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server
-
copy
public boolean copy(Path src, Path dst) throws AccessControlException, FileAlreadyExistsException, FileNotFoundException, ParentNotDirectoryException, UnsupportedFileSystemException, IOException Copy file from src to dest. Seecopy(Path, Path, boolean, boolean)- Parameters:
src- src.dst- dst.- Returns:
- if success copy true, not false.
- Throws:
AccessControlException- If access is denied.FileAlreadyExistsException- If filesrcalready exists.FileNotFoundException- if next file does not exist any more.ParentNotDirectoryException- If parent ofsrcis not a directory.UnsupportedFileSystemException- If file system forsrc/dstis not supported.IOException- If an I/O error occurred.
-
copy
public boolean copy(Path src, Path dst, boolean deleteSource, boolean overwrite) throws AccessControlException, FileAlreadyExistsException, FileNotFoundException, ParentNotDirectoryException, UnsupportedFileSystemException, IOException Copy from src to dst, optionally deleting src and overwriting dst.- Parameters:
src- src.dst- dst.deleteSource- - delete src if trueoverwrite- overwrite dst if true; throw IOException if dst exists and overwrite is false.- Returns:
- true if copy is successful
- Throws:
AccessControlException- If access is deniedFileAlreadyExistsException- Ifdstalready existsFileNotFoundException- Ifsrcdoes not existParentNotDirectoryException- If parent ofdstis not a directoryUnsupportedFileSystemException- If file system forsrcordstis not supportedIOException- If an I/O error occurred Exceptions applicable to file systems accessed over RPC:RpcClientException- If an exception occurred in the RPC clientRpcServerException- If an exception occurred in the RPC serverUnexpectedServerException- If server implementation throws undeclared exception to RPC server RuntimeExceptions:InvalidPathException- If pathdstis invalid
-