Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.archive.util
Class FileUtils

    java.lang.Object
      org.archive.util.FileUtils

    public class FileUtils

extends java.lang.Object

Utility methods for manipulating files and directories.

Author:
  John Erik Halse

Field Summary
`static java.io.File` | `TMPDIR`

Method Summary
`static boolean` | `copyFile(java.io.File src, java.io.File dest)` Copy the src file to the destination.
`static boolean` | `copyFile(java.io.File src, java.io.File dest, boolean overwrite)` Copy the src file to the destination.
`static boolean` | `copyFile(java.io.File src, java.io.File dest, long extent)` Copy up to extent bytes of the source file to the destination
`static boolean` | `copyFile(java.io.File src, java.io.File dest, long extent, boolean overwrite)` Copy up to extent bytes of the source file to the destination
`static void` | `copyFiles(java.io.File src, java.io.File dest)` Recursively copy all files from one directory to another.
`static void` | `copyFiles(java.io.File src, java.io.FilenameFilter filter, java.io.File dest, boolean inSortedOrder, boolean overwrite)` Recursively copy all files from one directory to another.
`static void` | `copyFiles(java.io.File src, java.io.FilenameFilter filter, java.io.File dest, boolean inSortedOrder, boolean overwrite, java.util.List<java.io.IOException> exceptions)` Recursively copy all files from one directory to another.
`static int` | `copyFiles(java.io.File srcDir, java.util.Set srcFile, java.io.File dest)`
`static boolean` | `deleteDir(java.io.File dir)` Deletes all files and subdirectories under dir.
`static java.io.File[]` | `getFilesWithPrefix(java.io.File dir, java.lang.String prefix)` Get a list of all files in directory that have passed prefix.
`static java.io.FileFilter` | `getRegexpFileFilter(java.lang.String regexp)` Get a @link java.io.FileFilter that filters files based on a regular expression.
`static java.lang.String[]` | `getSortedDirContent(java.io.File src, java.io.FilenameFilter filter)`
`static java.io.File` | `isReadable(java.io.File f)` Test file exists and is readable.
`static boolean` | `isReadableWithExtensionAndMagic(java.io.File f, java.lang.String uncompressedExtension, java.lang.String magic)`
`static java.io.File` | `maybeRelative(java.io.File context, java.lang.String path)` Turn path into a File, relative to context (which may be ignored if path is absolute).
`static java.lang.String` | `readFileAsString(java.io.File file)` Utility method to read an entire file as a String.
`static void` | `syncDirectories(java.io.File src, java.io.FilenameFilter filter, java.io.File tgt)` Use for case where files are being added to src.
`protected static void` | `workaroundCopyFile(java.io.File src, java.io.File dest)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### TMPDIR

    public static final java.io.File TMPDIR

Method Detail

### copyFiles

    public static int copyFiles(java.io.File srcDir,
                                java.util.Set srcFile,
                                java.io.File dest)
                         throws java.io.IOException

  Throws:
    `java.io.IOException`

### copyFiles

    public static void copyFiles(java.io.File src,
                                 java.io.File dest)
                          throws java.io.IOException

  Recursively copy all files from one directory to another.

  Parameters:
    `src` - file or directory to copy from.
    `dest` - file or directory to copy to.
  Throws:
    `java.io.IOException`

### getSortedDirContent

    public static java.lang.String[] getSortedDirContent(java.io.File src,
                                                         java.io.FilenameFilter filter)

  Parameters:
    `src` - Directory of files to fetch.
    `filter` - Filter to apply to filenames.
  Returns:
    Files in directory sorted.

### copyFiles

    public static void copyFiles(java.io.File src,
                                 java.io.FilenameFilter filter,
                                 java.io.File dest,
                                 boolean inSortedOrder,
                                 boolean overwrite)
                          throws java.io.IOException

  Recursively copy all files from one directory to another.

  Parameters:
    `src` - File or directory to copy from.
    `filter` - Filename filter to apply to src. May be null if no filtering wanted.
    `dest` - File or directory to copy to.
    `inSortedOrder` - Copy in order of natural sort.
    `overwrite` - If target file already exits, and this parameter is true, overwrite target file (We do this by first deleting the target file before we begin the copy).
  Throws:
    `java.io.IOException`

### copyFiles

    public static void copyFiles(java.io.File src,
                                 java.io.FilenameFilter filter,
                                 java.io.File dest,
                                 boolean inSortedOrder,
                                 boolean overwrite,
                                 java.util.List<java.io.IOException> exceptions)
                          throws java.io.IOException

  Recursively copy all files from one directory to another.

  Parameters:
    `src` - File or directory to copy from.
    `filter` - Filename filter to apply to src. May be null if no filtering wanted.
    `dest` - File or directory to copy to.
    `inSortedOrder` - Copy in order of natural sort.
    `overwrite` - If target file already exits, and this parameter is true, overwrite target file (We do this by first deleting the target file before we begin the copy).
    `exceptions` - if non-null, add any individual-file IOExceptions to this List rather than throwing, and proceed with the deep copy
  Throws:
    `java.io.IOException`

### copyFile

    public static boolean copyFile(java.io.File src,
                                   java.io.File dest)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException

  Copy the src file to the destination.

  Parameters:
    `src` -
    `dest` -
  Returns:
    True if the extent was greater than actual bytes copied.
  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

### copyFile

    public static boolean copyFile(java.io.File src,
                                   java.io.File dest,
                                   boolean overwrite)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException

  Copy the src file to the destination.

  Parameters:
    `src` -
    `dest` -
    `overwrite` - If target file already exits, and this parameter is true, overwrite target file (We do this by first deleting the target file before we begin the copy).
  Returns:
    True if the extent was greater than actual bytes copied.
  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

### copyFile

    public static boolean copyFile(java.io.File src,
                                   java.io.File dest,
                                   long extent)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException

  Copy up to extent bytes of the source file to the destination

  Parameters:
    `src` -
    `dest` -
    `extent` - Maximum number of bytes to copy
  Returns:
    True if the extent was greater than actual bytes copied.
  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

### copyFile

    public static boolean copyFile(java.io.File src,
                                   java.io.File dest,
                                   long extent,
                                   boolean overwrite)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException

  Copy up to extent bytes of the source file to the destination

  Parameters:
    `src` -
    `dest` -
    `extent` - Maximum number of bytes to copy
    `overwrite` - If target file already exits, and this parameter is true, overwrite target file (We do this by first deleting the target file before we begin the copy).
  Returns:
    True if the extent was greater than actual bytes copied.
  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

### workaroundCopyFile

    protected static void workaroundCopyFile(java.io.File src,
                                             java.io.File dest)
                                      throws java.io.IOException

  Throws:
    `java.io.IOException`

### deleteDir

    public static boolean deleteDir(java.io.File dir)

  Deletes all files and subdirectories under dir.

  Parameters:
    `dir` -
  Returns:
    true if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.

### readFileAsString

    public static java.lang.String readFileAsString(java.io.File file)
                                             throws java.io.IOException

  Utility method to read an entire file as a String.

  Parameters:
    `file` -
  Returns:
    File as String.
  Throws:
    `java.io.IOException`

### getFilesWithPrefix

    public static java.io.File[] getFilesWithPrefix(java.io.File dir,
                                                    java.lang.String prefix)

  Get a list of all files in directory that have passed prefix.

  Parameters:
    `dir` - Dir to look in.
    `prefix` - Basename of files to look for. Compare is case insensitive.
  Returns:
    List of files in dir that start w/ passed basename.

### getRegexpFileFilter

    public static java.io.FileFilter getRegexpFileFilter(java.lang.String regexp)

  Get a @link java.io.FileFilter that filters files based on a regular expression.

  Parameters:
    `regexp` - the regular expression the files must match.
  Returns:
    the newly created filter.

### syncDirectories

    public static void syncDirectories(java.io.File src,
                                       java.io.FilenameFilter filter,
                                       java.io.File tgt)
                                throws java.io.IOException

  Use for case where files are being added to src. Will break off copy when tgt is same as src.

  Parameters:
    `src` - Source directory to copy from.
    `tgt` - Target to copy to.
    `filter` - Filter to apply to files to copy.
  Throws:
    `java.io.IOException`

### isReadable

    public static java.io.File isReadable(java.io.File f)
                                   throws java.io.IOException

  Test file exists and is readable.

  Parameters:
    `f` - File to test.
  Throws:
    `java.io.IOException` - If file does not exist or is not unreadable.

### isReadableWithExtensionAndMagic

    public static boolean isReadableWithExtensionAndMagic(java.io.File f,
                                                          java.lang.String uncompressedExtension,
                                                          java.lang.String magic)
                                                   throws java.io.IOException

  Parameters:
    `f` - File to test.
  Returns:
    True if file is readable, has uncompressed extension, and magic string at file start.
  Throws:
    `java.io.IOException` - If file does not exist or is not readable.

### maybeRelative

    public static java.io.File maybeRelative(java.io.File context,
                                             java.lang.String path)

  Turn path into a File, relative to context (which may be ignored if path is absolute).

  Parameters:
    `context` - File context if path is relative
    `path` - String path to make into a File
  Returns:
    File created

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2008 Internet Archive. All Rights Reserved.