org.apache.hadoop.fs
Class FileContext.Util

java.lang.Object
  extended by org.apache.hadoop.fs.FileContext.Util
Enclosing class:
FileContext

public class FileContext.Util
extends Object

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
FileContext.Util()
           
 
Method Summary
 boolean copy(Path src, Path dst)
          Copy file from src to dest.
 boolean copy(Path src, Path dst, boolean deleteSource, boolean overwrite)
          Copy from src to dst, optionally deleting src and overwriting dst.
 boolean exists(Path f)
          Does the file exist? Note: Avoid using this method if you already have FileStatus in hand.
 ContentSummary getContentSummary(Path f)
          Return the ContentSummary of path f.
 FileStatus[] globStatus(Path pathPattern)
          Return all the files that match filePattern and are not checksum files.
 FileStatus[] 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.
 RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive)
          List the statuses and block locations of the files in the given path.
 FileStatus[] listStatus(Path f)
          List the statuses of the files/directories in the given path if the path is a directory.
 FileStatus[] listStatus(Path[] files)
          See listStatus(Path[], PathFilter)
 FileStatus[] listStatus(Path[] files, PathFilter filter)
          Filter files/directories in the given list of paths using user-supplied path filter.
 FileStatus[] listStatus(Path f, PathFilter filter)
          Filter files/directories in the given path using the user-supplied path filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileContext.Util

public FileContext.Util()
Method Detail

exists

public boolean exists(Path f)
               throws org.apache.hadoop.security.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
Throws:
org.apache.hadoop.security.AccessControlException - If access is denied
IOException - If an I/O error occurred
UnsupportedFileSystemException - If file system for f is not supported Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server

getContentSummary

public ContentSummary getContentSummary(Path f)
                                 throws org.apache.hadoop.security.AccessControlException,
                                        FileNotFoundException,
                                        UnsupportedFileSystemException,
                                        IOException
Return the ContentSummary of path f.

Parameters:
f - path
Returns:
the ContentSummary of path f.
Throws:
org.apache.hadoop.security.AccessControlException - If access is denied
FileNotFoundException - If f does not exist
UnsupportedFileSystemException - If file system for f is not supported
IOException - If an I/O error occurred Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server

listStatus

public FileStatus[] listStatus(Path[] files)
                        throws org.apache.hadoop.security.AccessControlException,
                               FileNotFoundException,
                               IOException
See listStatus(Path[], PathFilter)

Throws:
org.apache.hadoop.security.AccessControlException
FileNotFoundException
IOException

listStatus

public FileStatus[] listStatus(Path f,
                               PathFilter filter)
                        throws org.apache.hadoop.security.AccessControlException,
                               FileNotFoundException,
                               UnsupportedFileSystemException,
                               IOException
Filter files/directories in the given path using the user-supplied path filter.

Parameters:
f - is the path name
filter - is the user-supplied path filter
Returns:
an array of FileStatus objects for the files under the given path after applying the filter
Throws:
org.apache.hadoop.security.AccessControlException - If access is denied
FileNotFoundException - If f does not exist
UnsupportedFileSystemException - If file system for pathPattern is not supported
IOException - If an I/O error occurred Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server

listStatus

public FileStatus[] listStatus(Path[] files,
                               PathFilter filter)
                        throws org.apache.hadoop.security.AccessControlException,
                               FileNotFoundException,
                               IOException
Filter files/directories in the given list of paths using user-supplied path filter.

Parameters:
files - is a list of paths
filter - is the filter
Returns:
a list of statuses for the files under the given paths after applying the filter
Throws:
org.apache.hadoop.security.AccessControlException - If access is denied
FileNotFoundException - If a file in files does not exist
IOException - If an I/O error occurred Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server

listStatus

public FileStatus[] listStatus(Path f)
                        throws org.apache.hadoop.security.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:
org.apache.hadoop.security.AccessControlException - If access is denied
FileNotFoundException - If f does not exist
UnsupportedFileSystemException - If file system for f is not supported
IOException - If an I/O error occurred Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server

listFiles

public RemoteIterator<LocatedFileStatus> listFiles(Path f,
                                                   boolean recursive)
                                            throws org.apache.hadoop.security.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 path
recursive - 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:
org.apache.hadoop.security.AccessControlException - If access is denied
FileNotFoundException - If f does not exist
UnsupportedFileSystemException - If file system for f is not supported
IOException - If an I/O error occurred Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server

globStatus

public FileStatus[] globStatus(Path pathPattern)
                        throws org.apache.hadoop.security.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: character a must be lexicographically less than or equal to character b.

[^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 regular expression specifying a pth pattern
Returns:
an array of paths that match the path pattern
Throws:
org.apache.hadoop.security.AccessControlException - If access is denied
UnsupportedFileSystemException - If file system for pathPattern is not supported
IOException - If an I/O error occurred Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server

globStatus

public FileStatus[] globStatus(Path pathPattern,
                               PathFilter filter)
                        throws org.apache.hadoop.security.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 - regular expression specifying the path pattern
filter - user-supplied path filter
Returns:
an array of FileStatus objects
Throws:
org.apache.hadoop.security.AccessControlException - If access is denied
UnsupportedFileSystemException - If file system for pathPattern is not supported
IOException - If an I/O error occurred Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server

copy

public boolean copy(Path src,
                    Path dst)
             throws org.apache.hadoop.security.AccessControlException,
                    FileAlreadyExistsException,
                    FileNotFoundException,
                    ParentNotDirectoryException,
                    UnsupportedFileSystemException,
                    IOException
Copy file from src to dest. See copy(Path, Path, boolean, boolean)

Throws:
org.apache.hadoop.security.AccessControlException
FileAlreadyExistsException
FileNotFoundException
ParentNotDirectoryException
UnsupportedFileSystemException
IOException

copy

public boolean copy(Path src,
                    Path dst,
                    boolean deleteSource,
                    boolean overwrite)
             throws org.apache.hadoop.security.AccessControlException,
                    FileAlreadyExistsException,
                    FileNotFoundException,
                    ParentNotDirectoryException,
                    UnsupportedFileSystemException,
                    IOException
Copy from src to dst, optionally deleting src and overwriting dst.

Parameters:
src -
dst -
deleteSource - - delete src if true
overwrite - overwrite dst if true; throw IOException if dst exists and overwrite is false.
Returns:
true if copy is successful
Throws:
org.apache.hadoop.security.AccessControlException - If access is denied
FileAlreadyExistsException - If dst already exists
FileNotFoundException - If src does not exist
ParentNotDirectoryException - If parent of dst is not a directory
UnsupportedFileSystemException - If file system for src or dst is not supported
IOException - If an I/O error occurred Exceptions applicable to file systems accessed over RPC:
RpcClientException - If an exception occurred in the RPC client
RpcServerException - If an exception occurred in the RPC server
UnexpectedServerException - If server implementation throws undeclared exception to RPC server RuntimeExceptions:
InvalidPathException - If path dst is invalid


Copyright © 2012 Apache Software Foundation. All Rights Reserved.