Class PathUtils
- java.lang.Object
-
- fr.ens.biologie.genomique.eoulsan.util.hadoop.PathUtils
-
public final class PathUtils extends Object
This class define utility method to manipulate the Hadoop Path object.- Since:
- 1.0
- Author:
- Laurent Jourdren
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPathUtils.PrefixPathFilterSimple PathFilter to filter Paths with their beginningstatic classPathUtils.SuffixPathFilterSimple PathFilter to filter Paths with their suffix
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckExistingDirectoryFile(org.apache.hadoop.fs.Path directory, org.apache.hadoop.conf.Configuration conf, String msgFileType)Check if a directory existsstatic voidcheckExistingFile(org.apache.hadoop.fs.Path file, org.apache.hadoop.conf.Configuration conf, String msgFileType)Check if a file existsstatic voidcheckExistingStandardFile(org.apache.hadoop.fs.Path file, org.apache.hadoop.conf.Configuration conf, String msgFileType)Check if a file existsstatic voidcheckExistingStandardFileOrDirectory(org.apache.hadoop.fs.Path file, org.apache.hadoop.conf.Configuration conf, String msgFileType)Check if a file existsstatic booleanconcat(List<org.apache.hadoop.fs.Path> paths, org.apache.hadoop.fs.Path dstPath, boolean deleteSource, boolean overwrite, org.apache.hadoop.conf.Configuration conf)Copy all files in a directory to one output file (merge).static booleanconcat(List<org.apache.hadoop.fs.Path> paths, org.apache.hadoop.fs.Path dstPath, boolean deleteSource, boolean overwrite, org.apache.hadoop.conf.Configuration conf, String addString)Copy all files in a directory to one output file (merge).static booleanconcat(List<org.apache.hadoop.fs.Path> paths, org.apache.hadoop.fs.Path dstPath, org.apache.hadoop.conf.Configuration conf)Copy all files in a directory to one output file (merge).static booleancopy(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, boolean overwrite, org.apache.hadoop.conf.Configuration conf)Copy file from a path to another path.static booleancopy(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf)Copy file from a path to another path.static booleancopyAndCompressInputStreamToPath(InputStream is, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf)Copy bytes from an InputStream to a path.static booleancopyAndCompressLocalFileToPath(File srcFile, org.apache.hadoop.fs.Path destPath, boolean removeSrcFile, org.apache.hadoop.conf.Configuration conf)Copy a local file to a pathstatic booleancopyAndCompressLocalFileToPath(File srcFile, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf)Copy a local file to a pathstatic booleancopyFromPathToLocalFile(org.apache.hadoop.fs.Path srcPath, File destFile, boolean removeOriginalFile, org.apache.hadoop.conf.Configuration conf)Copy a file from a path to a local filestatic booleancopyFromPathToLocalFile(org.apache.hadoop.fs.Path srcPath, File destFile, org.apache.hadoop.conf.Configuration conf)Copy a file from a path to a local file.static longcopyInputStreamToPath(InputStream is, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf)Copy bytes from an InputStream to a path.static booleancopyLocalFileToPath(File srcFile, org.apache.hadoop.fs.Path destPath, boolean removeSrcFile, org.apache.hadoop.conf.Configuration conf)Copy a local file to a pathstatic booleancopyLocalFileToPath(File srcFile, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf)Copy a local file to a pathstatic voidcopyMerge(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, boolean deleteSource, org.apache.hadoop.conf.Configuration conf)Merge several file of a directory into one file.static voidcopyMerge(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, boolean deleteSource, org.apache.hadoop.conf.Configuration conf, String addString)Merge several file of a directory into one file.static voidcopyMerge(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf)Merge several file of a directory into one file.static InputStreamcreateInputStream(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf)Create an input stream from a path.static OutputStreamcreateOutputStream(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf)Create an output stream from a path.static org.apache.hadoop.fs.PathcreateTempPath(org.apache.hadoop.fs.Path directory, String prefix, String suffix, org.apache.hadoop.conf.Configuration conf)Create a new temporary path.static booleanexists(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf)Test if a path existsstatic booleanfullyDelete(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf)Fully delete a file of the content of a directorystatic longgetSize(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf)Get the length of a file.static booleanisExistingDirectoryFile(org.apache.hadoop.fs.Path directory, org.apache.hadoop.conf.Configuration conf)Check if a directory existsstatic booleanisFile(org.apache.hadoop.fs.Path file, org.apache.hadoop.conf.Configuration conf)Check if a file existsstatic List<org.apache.hadoop.fs.Path>listPathsByPrefix(org.apache.hadoop.fs.Path dir, String prefix, boolean allowCompressedExtension, org.apache.hadoop.conf.Configuration conf)Return a list of the file of a pathstatic List<org.apache.hadoop.fs.Path>listPathsByPrefix(org.apache.hadoop.fs.Path dir, String prefix, org.apache.hadoop.conf.Configuration conf)Return a list of the file of a pathstatic List<org.apache.hadoop.fs.Path>listPathsBySuffix(org.apache.hadoop.fs.Path dir, String suffix, boolean allowCompressedExtension, org.apache.hadoop.conf.Configuration conf)Return a list of the file of a pathstatic List<org.apache.hadoop.fs.Path>listPathsBySuffix(org.apache.hadoop.fs.Path dir, String suffix, org.apache.hadoop.conf.Configuration conf)Return a list of the file of a pathstatic booleanmkdirs(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf)Create a directory.static booleanmove(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, boolean overwrite, org.apache.hadoop.conf.Configuration conf)Move file from a path to another path.static booleanmove(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf)Move file from a path to another path.static org.apache.hadoop.fs.PathnewPathWithOtherExtension(org.apache.hadoop.fs.Path path, String extension)Create a new path with the same parent directory and basename but without another extension.static voidunZipPathToLocalFile(org.apache.hadoop.fs.Path srcPath, File outputDir, boolean removeOriginalZipFile, org.apache.hadoop.conf.Configuration conf)Unzip a zip file on local file system.static voidunZipPathToLocalFile(org.apache.hadoop.fs.Path path, File outputDir, org.apache.hadoop.conf.Configuration conf)Unzip a zip file on local file system.
-
-
-
Method Detail
-
createInputStream
public static InputStream createInputStream(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOException
Create an input stream from a path.- Parameters:
path- Path of the file to openconf- configuration- Returns:
- an InputStream
- Throws:
IOException- if an error occurs while creating InputStream
-
createOutputStream
public static OutputStream createOutputStream(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOException
Create an output stream from a path.- Parameters:
path- Path of the file to openconf- configuration- Returns:
- an InputStream
- Throws:
IOException- if an error occurs while creating InputStream
-
getSize
public static long getSize(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOExceptionGet the length of a file.- Parameters:
path- Path of the file to openconf- configuration- Returns:
- an InputStream
- Throws:
IOException- if an error occurs while creating InputStream
-
copyFromPathToLocalFile
public static boolean copyFromPathToLocalFile(org.apache.hadoop.fs.Path srcPath, File destFile, org.apache.hadoop.conf.Configuration conf) throws IOExceptionCopy a file from a path to a local file. Don't remove original file.- Parameters:
srcPath- Path of the file to copydestFile- Destination fileconf- Configuration object * @return true if the copy is successful- Throws:
IOException- if an error occurs while copying file
-
copyFromPathToLocalFile
public static boolean copyFromPathToLocalFile(org.apache.hadoop.fs.Path srcPath, File destFile, boolean removeOriginalFile, org.apache.hadoop.conf.Configuration conf) throws IOExceptionCopy a file from a path to a local file- Parameters:
srcPath- Path of the file to copydestFile- Destination fileremoveOriginalFile- true if the original file must be deletedconf- Configuration object- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying file
-
copyLocalFileToPath
public static boolean copyLocalFileToPath(File srcFile, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf) throws IOException
Copy a local file to a path- Parameters:
srcFile- source filedestPath- destination pathconf- Configuration object- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying file
-
copyLocalFileToPath
public static boolean copyLocalFileToPath(File srcFile, org.apache.hadoop.fs.Path destPath, boolean removeSrcFile, org.apache.hadoop.conf.Configuration conf) throws IOException
Copy a local file to a path- Parameters:
srcFile- source filedestPath- destination pathremoveSrcFile- true if the source file must be removedconf- Configuration object- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying file
-
copyInputStreamToPath
public static long copyInputStreamToPath(InputStream is, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf) throws IOException
Copy bytes from an InputStream to a path.- Parameters:
is- the InputStream to read fromdestPath- destination pathconf- Configuration object- Returns:
- the number of bytes copied
- Throws:
IOException- In case of an I/O problem
-
copyAndCompressLocalFileToPath
public static boolean copyAndCompressLocalFileToPath(File srcFile, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf) throws IOException
Copy a local file to a path- Parameters:
srcFile- source filedestPath- destination pathconf- Configuration object- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying file
-
copyAndCompressLocalFileToPath
public static boolean copyAndCompressLocalFileToPath(File srcFile, org.apache.hadoop.fs.Path destPath, boolean removeSrcFile, org.apache.hadoop.conf.Configuration conf) throws IOException
Copy a local file to a path- Parameters:
srcFile- source filedestPath- destination pathremoveSrcFile- true if the source file must be removedconf- Configuration object- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying file
-
copyAndCompressInputStreamToPath
public static boolean copyAndCompressInputStreamToPath(InputStream is, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf) throws IOException
Copy bytes from an InputStream to a path.- Parameters:
is- the InputStream to read fromdestPath- destination pathconf- Configuration object- Returns:
- the number of bytes copied
- Throws:
IOException- In case of an I/O problem
-
unZipPathToLocalFile
public static void unZipPathToLocalFile(org.apache.hadoop.fs.Path path, File outputDir, org.apache.hadoop.conf.Configuration conf) throws IOExceptionUnzip a zip file on local file system. Don't remove original zip file.- Parameters:
path- Path of the zip fileoutputDir- Output directory of the content of the zip fileconf- Configuration object- Throws:
IOException- if an error occurs while unzipping the file
-
unZipPathToLocalFile
public static void unZipPathToLocalFile(org.apache.hadoop.fs.Path srcPath, File outputDir, boolean removeOriginalZipFile, org.apache.hadoop.conf.Configuration conf) throws IOExceptionUnzip a zip file on local file system.- Parameters:
srcPath- Path of the zip fileoutputDir- Output directory of the content of the zip fileremoveOriginalZipFile- true if the original zip file must be removedconf- Configuration object- Throws:
IOException- if an error occurs while unzipping the file
-
fullyDelete
public static boolean fullyDelete(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOExceptionFully delete a file of the content of a directory- Parameters:
path- Path of the fileconf- Configuration Object- Returns:
- true if the Path is successfully removed
- Throws:
IOException- if cannot delete the file
-
copyMerge
public static void copyMerge(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf) throws IOExceptionMerge several file of a directory into one file.- Parameters:
srcPath- source directory pathdestPath- destination pathconf- Configuration object- Throws:
IOException- if an error occurs while merging files
-
copyMerge
public static void copyMerge(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, boolean deleteSource, org.apache.hadoop.conf.Configuration conf) throws IOExceptionMerge several file of a directory into one file.- Parameters:
srcPath- source directory pathdestPath- destination pathdeleteSource- delete source filesconf- Configuration object- Throws:
IOException- if an error occurs while merging files
-
copyMerge
public static void copyMerge(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, boolean deleteSource, org.apache.hadoop.conf.Configuration conf, String addString) throws IOExceptionMerge several file of a directory into one file.- Parameters:
srcPath- source directory pathdestPath- destination pathdeleteSource- delete source filesconf- Configuration objectaddString- string to add- Throws:
IOException- if an error occurs while merging files
-
newPathWithOtherExtension
public static org.apache.hadoop.fs.Path newPathWithOtherExtension(org.apache.hadoop.fs.Path path, String extension)Create a new path with the same parent directory and basename but without another extension.- Parameters:
path- base path to useextension- extension to add- Returns:
- a new Path object
-
listPathsByPrefix
public static List<org.apache.hadoop.fs.Path> listPathsByPrefix(org.apache.hadoop.fs.Path dir, String prefix, org.apache.hadoop.conf.Configuration conf) throws IOException
Return a list of the file of a path- Parameters:
dir- Path of the directoryprefix- filter on suffixconf- Configuration- Returns:
- a list of Path
- Throws:
IOException- if an error occurs while listing the directory
-
listPathsByPrefix
public static List<org.apache.hadoop.fs.Path> listPathsByPrefix(org.apache.hadoop.fs.Path dir, String prefix, boolean allowCompressedExtension, org.apache.hadoop.conf.Configuration conf) throws IOException
Return a list of the file of a path- Parameters:
dir- Path of the directoryprefix- filter on suffixallowCompressedExtension- Allow compressed extensionsconf- Configuration- Returns:
- a list of Path
- Throws:
IOException- if an error occurs while listing the directory
-
listPathsBySuffix
public static List<org.apache.hadoop.fs.Path> listPathsBySuffix(org.apache.hadoop.fs.Path dir, String suffix, org.apache.hadoop.conf.Configuration conf) throws IOException
Return a list of the file of a path- Parameters:
dir- Path of the directorysuffix- filter on suffixconf- Configuration- Returns:
- a list of Path
- Throws:
IOException- if an error occurs while listing the directory
-
listPathsBySuffix
public static List<org.apache.hadoop.fs.Path> listPathsBySuffix(org.apache.hadoop.fs.Path dir, String suffix, boolean allowCompressedExtension, org.apache.hadoop.conf.Configuration conf) throws IOException
Return a list of the file of a path- Parameters:
dir- Path of the directorysuffix- filter on suffixallowCompressedExtension- Allow compressed extensionsconf- Configuration- Returns:
- a list of Path
- Throws:
IOException- if an error occurs while listing the directory
-
createTempPath
public static org.apache.hadoop.fs.Path createTempPath(org.apache.hadoop.fs.Path directory, String prefix, String suffix, org.apache.hadoop.conf.Configuration conf) throws IOExceptionCreate a new temporary path. Nothing is created on the file system.- Parameters:
directory- parent directory of the temporary file to createprefix- Prefix of the temporary filesuffix- suffix of the temporary file- Returns:
- the new temporary file
- Throws:
IOException- if there is an error creating the temporary directory
-
concat
public static boolean concat(List<org.apache.hadoop.fs.Path> paths, org.apache.hadoop.fs.Path dstPath, org.apache.hadoop.conf.Configuration conf) throws IOException
Copy all files in a directory to one output file (merge).- Parameters:
paths- list of path files to concatdstPath- destination pathconf- Configuration- Throws:
IOException
-
concat
public static boolean concat(List<org.apache.hadoop.fs.Path> paths, org.apache.hadoop.fs.Path dstPath, boolean deleteSource, boolean overwrite, org.apache.hadoop.conf.Configuration conf) throws IOException
Copy all files in a directory to one output file (merge).- Parameters:
paths- list of path files to concatdstPath- destination pathdeleteSource- true if the original files must be deletedoverwrite- true if an existing destination file must be deletedconf- Configuration- Throws:
IOException
-
concat
public static boolean concat(List<org.apache.hadoop.fs.Path> paths, org.apache.hadoop.fs.Path dstPath, boolean deleteSource, boolean overwrite, org.apache.hadoop.conf.Configuration conf, String addString) throws IOException
Copy all files in a directory to one output file (merge).- Parameters:
paths- list of path files to concatdstPath- destination pathdeleteSource- true if the original files must be deletedoverwrite- true if an existing destination file must be deletedconf- ConfigurationaddString- string to add- Throws:
IOException
-
checkExistingFile
public static void checkExistingFile(org.apache.hadoop.fs.Path file, org.apache.hadoop.conf.Configuration conf, String msgFileType) throws IOExceptionCheck if a file exists- Parameters:
file- File to testconf- ConfigurationmsgFileType- message for the description of the file- Throws:
IOException- if the file doesn't exists
-
checkExistingDirectoryFile
public static void checkExistingDirectoryFile(org.apache.hadoop.fs.Path directory, org.apache.hadoop.conf.Configuration conf, String msgFileType) throws IOExceptionCheck if a directory exists- Parameters:
directory- directory to test * @param conf Configurationconf- the configuration objectmsgFileType- message for the description of the file- Throws:
IOException- if the file doesn't exists
-
isExistingDirectoryFile
public static boolean isExistingDirectoryFile(org.apache.hadoop.fs.Path directory, org.apache.hadoop.conf.Configuration conf) throws IOExceptionCheck if a directory exists- Parameters:
directory- directory to test * @param conf Configurationconf- the configuration object- Returns:
- true is the directory exists
- Throws:
IOException
-
isFile
public static boolean isFile(org.apache.hadoop.fs.Path file, org.apache.hadoop.conf.Configuration conf) throws IOExceptionCheck if a file exists- Parameters:
file- file to testconf- Configuration- Returns:
- true is the directory exists
- Throws:
IOException
-
checkExistingStandardFile
public static void checkExistingStandardFile(org.apache.hadoop.fs.Path file, org.apache.hadoop.conf.Configuration conf, String msgFileType) throws IOExceptionCheck if a file exists- Parameters:
file- File to test * @param conf ConfigurationmsgFileType- message for the description of the file- Throws:
IOException- if the file doesn't exists
-
checkExistingStandardFileOrDirectory
public static void checkExistingStandardFileOrDirectory(org.apache.hadoop.fs.Path file, org.apache.hadoop.conf.Configuration conf, String msgFileType) throws IOExceptionCheck if a file exists- Parameters:
file- File to test * @param conf ConfigurationmsgFileType- message for the description of the file- Throws:
IOException- if the file doesn't exists
-
copy
public static boolean copy(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf) throws IOExceptionCopy file from a path to another path.- Parameters:
srcPath- source pathdestPath- destination pathconf- Configuration- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying
-
copy
public static boolean copy(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, boolean overwrite, org.apache.hadoop.conf.Configuration conf) throws IOExceptionCopy file from a path to another path.- Parameters:
srcPath- source pathdestPath- destination pathoverwrite- true if existing files must be overwrittenconf- Configuration- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying
-
move
public static boolean move(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, org.apache.hadoop.conf.Configuration conf) throws IOExceptionMove file from a path to another path.- Parameters:
srcPath- source pathdestPath- destination pathconf- Configuration- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying
-
move
public static boolean move(org.apache.hadoop.fs.Path srcPath, org.apache.hadoop.fs.Path destPath, boolean overwrite, org.apache.hadoop.conf.Configuration conf) throws IOExceptionMove file from a path to another path.- Parameters:
srcPath- source pathdestPath- destination pathoverwrite- true if existing files must be overwrittenconf- Configuration- Returns:
- true if the copy is successful
- Throws:
IOException- if an error occurs while copying
-
mkdirs
public static boolean mkdirs(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOExceptionCreate a directory. If parent directories don't exists create it.- Parameters:
path- Path of the directory to createconf- Configuration- Returns:
- true if the directory is successfully created
- Throws:
IOException- if an error occurs while creating the directory
-
exists
public static boolean exists(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOExceptionTest if a path exists- Parameters:
path- Path to testconf- Configuration- Returns:
- true if the path exists
- Throws:
IOException- if an error occurs while creating the directory
-
-