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

## phelps.io
Class Files

    java.lang.Object
      phelps.io.Files

public class Files
extends java.lang.Object

Extensions to `File`.

- `File` constructors: `getFile(String)`, `getCanonicalFile(String)`, `getFuzzyFile(File, String)`
- name tests: `isCompressed(String)`, `isBackup(String)`
- parsers: `getSuffix(String)`, `getRoot(String)`
- pretty printing: `relative(File, File)`, `shortpath(File, File)`
- UNIX `glob(String)`
- content manipulation: `toByteArray(File)`, `copy(File, File)`, `delete(File)`, `secureDelete(File)`

Version:
  $Revision: 1.5 $ $Date: 2005/01/02 10:59:06 $

Field Summary
`static int` | `BUFSIZ` Common size of disk blocks at the time of release (this can increase from release to release).
`static java.util.Comparator<java.io.File>` | `DICTIONARY_CASE_INSENSITIVE_ORDER` Comparator that sorts filenames (`File.getName()`), not full path, by {@link phelps.lang.Strings#DICTIONARY_CASE_INSENSITIVE_ORDER.

Method Summary
`static void` | `copy(java.io.File filein, java.io.File fileout)` Copies filein to fileout, creating parent directories as needed.
`static boolean` | `delete(java.io.File dir)` Delete directory, including all files and subdirectories.
`static java.io.File` | `getCanonicalFile(java.lang.String path)` Like `java.io.File#getCanonicalFile(String)` but also expands `~` to users home directory (as given by the `user.home` property).
`static java.lang.String` | `getEncoding(java.lang.String path)` Returns HTTP Content-Encoding (compression type) as guessed from path's suffix.
`static java.io.File` | `getFile(java.lang.String path)` Like `File.File(String)` but also expands `~user` to users home directory (as given by the `user.home` property).
`static java.io.File` | `getFuzzyFile(java.io.File base, java.lang.String path)` Returns existing file (not directory), looking around a little if necessary: (UNIX) `getCanonicalFile(String)` (WWW) if points to directory, tries adding "index.html" (compression) adding or removing a compression suffix If no existing file can be found, returns same as `getCanonicalFile(String)`.
`static java.lang.String` | `getRoot(java.lang.String filename)` Returns filename with suffix, if any, chopped off.
`static java.lang.String` | `getSuffix(java.io.File file)`
`static java.lang.String` | `getSuffix(java.lang.String filename)` Returns the portion of filename after and exclusive of the last dot (".").
`static java.lang.String` | `getTail(java.lang.String path)`
`static java.io.File[]` | `glob(java.lang.String pattern)` Returns array of File's matching UNIX glob pattern, with the extension that `**` searches the current directory and all subdirectories.
`static boolean` | `isBackup(java.lang.String filename)` Returns true if filename is a backup file (e.g., end with ".bkup", with possible additional compression suffix).
`static boolean` | `isCompressed(java.lang.String filename)` Returns true if filename has a compression suffix for a type we can handle, which are `.gz`, `.Z`, `.bzip2`/`.bz2`.
`static java.lang.String` | `relative(java.io.File base, java.io.File file)` Returns path of file relative to base.
`static boolean` | `renameTo(java.io.File file, java.io.File dest)` Like `File.renameTo(File)`, except guaranteed to work across file-systems, copying if necessary.
`static boolean` | `secureDelete(java.io.File file)` Securely deletes a file by first overwriting it with random data several times.
`static java.lang.String` | `shortpath(java.io.File base, java.io.File file)` Returns the shortest path: relative to base, relative to user home directory, or absolute.
`static byte[]` | `toByteArray(java.io.File file)`

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

Field Detail

### DICTIONARY_CASE_INSENSITIVE_ORDER

    public static final java.util.Comparator<java.io.File> DICTIONARY_CASE_INSENSITIVE_ORDER

  Comparator that sorts filenames (`File.getName()`), not full path, by {@link phelps.lang.Strings#DICTIONARY_CASE_INSENSITIVE_ORDER.

### BUFSIZ

    public static final int BUFSIZ

  Common size of disk blocks at the time of release (this can increase from release to release).

  See Also:
    Constant Field Values

Method Detail

### getFile

    public static java.io.File getFile(java.lang.String path)

  Like `File.File(String)` but also expands `~user` to users home directory (as given by the `user.home` property).

### getCanonicalFile

    public static java.io.File getCanonicalFile(java.lang.String path)
                                         throws java.io.IOException

  Like `java.io.File#getCanonicalFile(String)` but also expands `~` to users home directory (as given by the `user.home` property).

  Throws:
    `java.io.IOException`

### getFuzzyFile

    public static java.io.File getFuzzyFile(java.io.File base,
                                            java.lang.String path)
                                     throws java.io.IOException

  Returns existing file (not directory), looking around a little if necessary:
  - (UNIX) `getCanonicalFile(String)`
  - (WWW) if points to directory, tries adding "index.html"
  - (compression) adding or removing a compression suffix
  If no existing file can be found, returns same as `getCanonicalFile(String)`.

  Throws:
    `java.io.IOException`

### relative

    public static java.lang.String relative(java.io.File base,
                                            java.io.File file)

  Returns path of file relative to base.

### shortpath

    public static java.lang.String shortpath(java.io.File base,
                                             java.io.File file)

  Returns the shortest path: relative to base, relative to user home directory, or absolute.

### getRoot

    public static java.lang.String getRoot(java.lang.String filename)

  Returns filename with suffix, if any, chopped off.

### getTail

    public static java.lang.String getTail(java.lang.String path)

### getSuffix

    public static java.lang.String getSuffix(java.io.File file)

### getSuffix

    public static java.lang.String getSuffix(java.lang.String filename)

  Returns the portion of filename after and exclusive of the last dot (".").

### renameTo

    public static boolean renameTo(java.io.File file,
                                   java.io.File dest)

  Like `File.renameTo(File)`, except guaranteed to work across file-systems, copying if necessary.

### isCompressed

    public static boolean isCompressed(java.lang.String filename)

  Returns true if filename has a compression suffix for a type we can handle, which are `.gz`, `.Z`, `.bzip2`/`.bz2`.

### getEncoding

    public static java.lang.String getEncoding(java.lang.String path)

  Returns HTTP Content-Encoding (compression type) as guessed from path's suffix. No encoding and unknown encoding are returned as null;

### isBackup

    public static boolean isBackup(java.lang.String filename)

  Returns true if filename is a backup file (e.g., end with ".bkup", with possible additional compression suffix).

### glob

    public static java.io.File[] glob(java.lang.String pattern)
                               throws java.io.IOException

  Returns array of File's matching UNIX glob pattern, with the extension that `**` searches the current directory and all subdirectories. A glob pattern is related to a regular expression as follows: the glob `*` is equivalent to regexp `.*`., `?` to `.`, and `{one,two}` to `{(one|two)`. Also, the `~`, `.`, and `..` strings have their same meaning as in `getFile(String)`.

  Throws:
    `java.io.IOException`

### toByteArray

    public static byte[] toByteArray(java.io.File file)
                              throws java.io.IOException

  Throws:
    `java.io.IOException`

### copy

    public static void copy(java.io.File filein,
                            java.io.File fileout)
                     throws java.io.IOException

  Copies filein to fileout, creating parent directories as needed.

  Throws:
    `java.io.IOException`

### delete

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

  Delete directory, including all files and subdirectories.

### secureDelete

    public static boolean secureDelete(java.io.File file)
                                throws java.io.IOException

  Securely deletes a file by first overwriting it with random data several times.

  Returns:
    `true` iff successful
  Throws:
    `java.io.IOException`

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