public class FileUtils extends Object
Modifier and Type | Field and Description |
---|---|
static org.apache.hadoop.fs.PathFilter |
HIDDEN_FILES_PATH_FILTER |
Constructor and Description |
---|
FileUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
copy(org.apache.hadoop.fs.FileSystem srcFS,
org.apache.hadoop.fs.Path src,
org.apache.hadoop.fs.FileSystem dstFS,
org.apache.hadoop.fs.Path dst,
boolean deleteSource,
boolean overwrite,
org.apache.hadoop.conf.Configuration conf)
Copies files between filesystems.
|
static boolean |
equalsFileSystem(org.apache.hadoop.fs.FileSystem fs1,
org.apache.hadoop.fs.FileSystem fs2)
Determine if two objects reference the same file system.
|
static String |
escapePathName(String path) |
static String |
escapePathName(String path,
String defaultPath)
Escapes a path name.
|
static List<org.apache.hadoop.fs.FileStatus> |
getFileStatusRecurse(org.apache.hadoop.fs.Path path,
int level,
org.apache.hadoop.fs.FileSystem fs)
Get all file status from a root path and recursively go deep into certain levels.
|
static boolean |
isDirEmpty(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Utility method that determines if a specified directory already has
contents (non-hidden files) or not - useful to determine if an
immutable table already has contents, for example.
|
static void |
listStatusRecursively(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.FileStatus fileStatus,
List<org.apache.hadoop.fs.FileStatus> results)
Recursively lists status for all files starting from a particular directory (or individual file
as base case).
|
static void |
makeDir(org.apache.hadoop.fs.Path path,
org.apache.hadoop.conf.Configuration conf) |
static String |
makePartName(List<String> partCols,
List<String> vals) |
static String |
makePartName(List<String> partCols,
List<String> vals,
String defaultStr)
Makes a valid partition name.
|
static org.apache.hadoop.fs.Path |
makeQualified(org.apache.hadoop.fs.Path path,
org.apache.hadoop.conf.Configuration conf)
Variant of Path.makeQualified that qualifies the input path against the default file system
indicated by the configuration
This does not require a FileSystem handle in most cases - only requires the Filesystem URI.
|
static boolean |
mkdir(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path f)
Creates the directory and all necessary parent directories.
|
static boolean |
moveToTrash(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path f,
org.apache.hadoop.conf.Configuration conf,
boolean purge)
Move a particular file or directory to the trash.
|
static boolean |
pathHasSnapshotSubDir(org.apache.hadoop.fs.Path p,
org.apache.hadoop.fs.FileSystem fs)
Check if the path contains a subdirectory named '.snapshot'
|
static boolean |
rename(org.apache.hadoop.fs.FileSystem srcFs,
org.apache.hadoop.fs.FileSystem destFs,
org.apache.hadoop.fs.Path srcPath,
org.apache.hadoop.fs.Path destPath)
Rename a file.
|
static String |
unescapePathName(String path) |
public static final org.apache.hadoop.fs.PathFilter HIDDEN_FILES_PATH_FILTER
public static boolean moveToTrash(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path f, org.apache.hadoop.conf.Configuration conf, boolean purge) throws IOException
fs
- FileSystem to usef
- path of file or directory to move to trash.conf
- configuration objectIOException
public static boolean copy(org.apache.hadoop.fs.FileSystem srcFS, org.apache.hadoop.fs.Path src, org.apache.hadoop.fs.FileSystem dstFS, org.apache.hadoop.fs.Path dst, boolean deleteSource, boolean overwrite, org.apache.hadoop.conf.Configuration conf) throws IOException
IOException
public static boolean mkdir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path f) throws IOException
fs
- FileSystem to usef
- path to create.IOException
- exception in creating the directorypublic static boolean rename(org.apache.hadoop.fs.FileSystem srcFs, org.apache.hadoop.fs.FileSystem destFs, org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath) throws IOException
FileSystem.rename(Path, Path)
, if the destPath already exists
and is a directory, this will NOT move the sourcePath into it. It will throw an IOException
instead.srcFs
- file system src paths are ondestFs
- file system dest paths are onsrcPath
- source file or directory to movedestPath
- destination file name. This must be a file and not an existing directory.IOException
- if fs.rename throws it, or if destPath already exists.public static String escapePathName(String path, String defaultPath)
path
- The path to escape.defaultPath
- The default name for the path, if the given path is empty or null.public static List<org.apache.hadoop.fs.FileStatus> getFileStatusRecurse(org.apache.hadoop.fs.Path path, int level, org.apache.hadoop.fs.FileSystem fs) throws IOException
path
- the root pathlevel
- the depth of directory to explorefs
- the file systemIOException
public static void listStatusRecursively(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.FileStatus fileStatus, List<org.apache.hadoop.fs.FileStatus> results) throws IOException
fs
- file systemfileStatus
- starting point in file systemresults
- receives enumeration of all files foundIOException
public static String makePartName(List<String> partCols, List<String> vals, String defaultStr)
partCols
- The partition keys' namesvals
- The partition valuesdefaultStr
- The default name given to a partition value if the respective value is empty or null.public static boolean equalsFileSystem(org.apache.hadoop.fs.FileSystem fs1, org.apache.hadoop.fs.FileSystem fs2)
fs1
- first file systemfs2
- second file systempublic static boolean pathHasSnapshotSubDir(org.apache.hadoop.fs.Path p, org.apache.hadoop.fs.FileSystem fs) throws IOException
p
- path to checkfs
- filesystem of the pathIOException
public static void makeDir(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws MetaException
MetaException
public static boolean isDirEmpty(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException
fs
- path
- IOException
public static org.apache.hadoop.fs.Path makeQualified(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOException
path
- path to be fully qualifiedconf
- Configuration fileIOException
Copyright © 2022 The Apache Software Foundation. All rights reserved.