org.apache.hadoop.fs
Class FileUtil

java.lang.Object
  extended by org.apache.hadoop.fs.FileUtil

public class FileUtil
extends Object

A collection of file-processing util methods


Nested Class Summary
static class FileUtil.HardLink
          Class for creating hardlinks.
 
Constructor Summary
FileUtil()
           
 
Method Summary
static int chmod(String filename, String perm)
          Change the permissions on a filename.
static void closeSocket(Socket sock)
           
static void closeStream(Closeable closeable)
           
static boolean copy(File src, FileSystem dstFS, Path dst, boolean deleteSource, Configuration conf)
          Copy local files to a FileSystem.
static boolean copy(FileSystem srcFS, Path src, File dst, boolean deleteSource, Configuration conf)
          Copy FileSystem files to local files.
static boolean copy(FileSystem srcFS, Path src, FileSystem dstFS, Path dst, boolean deleteSource, Configuration conf)
          Copy files between FileSystems.
static boolean copyMerge(FileSystem srcFS, Path srcDir, FileSystem dstFS, Path dstFile, boolean deleteSource, Configuration conf, String addString)
          Copy all files in a directory to one output file (merge).
static File createLocalTempFile(File basefile, String prefix, boolean isDeleteOnExit)
          Create a tmp file for a base file.
static boolean fullyDelete(File dir)
          Delete a directory and all its contents.
static void fullyDelete(FileSystem fs, Path dir)
          Recursively delete a directory.
static long getDU(File dir)
          Takes an input dir and returns the du on that local directory.
static String makeShellPath(File file)
          Convert a os-native filename to a path that works for the shell.
static String makeShellPath(String filename)
          Convert a os-native filename to a path that works for the shell.
static void readFully(InputStream in, byte[] buf, int off, int len)
           
static void skipFully(InputStream in, long len)
           
static int symLink(String target, String linkname)
          Create a soft link between a src and destination only on a local disk.
static void unZip(File inFile, File unzipDir)
          Given a File input it will unzip the file in a the unzip directory passed as the second parameter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

fullyDelete

public static boolean fullyDelete(File dir)
                           throws IOException
Delete a directory and all its contents. If we return false, the directory may be partially-deleted.

Throws:
IOException

fullyDelete

public static void fullyDelete(FileSystem fs,
                               Path dir)
                        throws IOException
Recursively delete a directory.

Parameters:
fs - FileSystem on which the path is present
dir - directory to recursively delete
Throws:
IOException

copy

public static boolean copy(FileSystem srcFS,
                           Path src,
                           FileSystem dstFS,
                           Path dst,
                           boolean deleteSource,
                           Configuration conf)
                    throws IOException
Copy files between FileSystems.

Throws:
IOException

copyMerge

public static boolean copyMerge(FileSystem srcFS,
                                Path srcDir,
                                FileSystem dstFS,
                                Path dstFile,
                                boolean deleteSource,
                                Configuration conf,
                                String addString)
                         throws IOException
Copy all files in a directory to one output file (merge).

Throws:
IOException

copy

public static boolean copy(File src,
                           FileSystem dstFS,
                           Path dst,
                           boolean deleteSource,
                           Configuration conf)
                    throws IOException
Copy local files to a FileSystem.

Throws:
IOException

copy

public static boolean copy(FileSystem srcFS,
                           Path src,
                           File dst,
                           boolean deleteSource,
                           Configuration conf)
                    throws IOException
Copy FileSystem files to local files.

Throws:
IOException

makeShellPath

public static String makeShellPath(String filename)
                            throws IOException
Convert a os-native filename to a path that works for the shell.

Parameters:
filename - The filename to convert
Returns:
The unix pathname
Throws:
IOException - on windows, there can be problems with the subprocess

makeShellPath

public static String makeShellPath(File file)
                            throws IOException
Convert a os-native filename to a path that works for the shell.

Parameters:
file - The filename to convert
Returns:
The unix pathname
Throws:
IOException - on windows, there can be problems with the subprocess

getDU

public static long getDU(File dir)
Takes an input dir and returns the du on that local directory. Very basic implementation.

Parameters:
dir - The input dir to get the disk space of this local dir
Returns:
The total disk space of the input local directory

unZip

public static void unZip(File inFile,
                         File unzipDir)
                  throws IOException
Given a File input it will unzip the file in a the unzip directory passed as the second parameter

Parameters:
inFile - The zip file as input
unzipDir - The unzip directory where to unzip the zip file.
Throws:
IOException

symLink

public static int symLink(String target,
                          String linkname)
                   throws IOException
Create a soft link between a src and destination only on a local disk. HDFS does not support this

Parameters:
target - the target for symlink
linkname - the symlink
Returns:
value returned by the command
Throws:
IOException

chmod

public static int chmod(String filename,
                        String perm)
                 throws IOException,
                        InterruptedException
Change the permissions on a filename.

Parameters:
filename - the name of the file to change
perm - the permission string
Returns:
the exit code from the command
Throws:
IOException
InterruptedException

createLocalTempFile

public static final File createLocalTempFile(File basefile,
                                             String prefix,
                                             boolean isDeleteOnExit)
                                      throws IOException
Create a tmp file for a base file.

Parameters:
basefile - the base file of the tmp
prefix - file name prefix of tmp
isDeleteOnExit - if true, the tmp will be deleted when the VM exits
Returns:
a newly created tmp file
Throws:
IOException - If a tmp file cannot created
See Also:
File.createTempFile(String, String, File), File.deleteOnExit()

readFully

public static void readFully(InputStream in,
                             byte[] buf,
                             int off,
                             int len)
                      throws IOException
Throws:
IOException

skipFully

public static void skipFully(InputStream in,
                             long len)
                      throws IOException
Throws:
IOException

closeSocket

public static void closeSocket(Socket sock)

closeStream

public static void closeStream(Closeable closeable)


Copyright © 2006 The Apache Software Foundation