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

## cc.mallet.util
Class FileUtils

    java.lang.Object
      cc.mallet.util.FileUtils

    public class FileUtils

extends java.lang.Object

Contains static utilities for manipulating files. Created: Thu Nov 20 15:14:16 2003

Version:
  $Id: FileUtils.java,v 1.1 2007/10/22 21:37:40 mccallum Exp $
Author:
  Charles Sutton

Method Summary
`static java.lang.String[]` | `readFile(java.io.File f)` Reads every line from a given text file.
`static java.lang.Object` | `readGzippedObject(java.io.File f)` Reads a serialized object from a file that has been compressed using gzip.
`static java.lang.Object` | `readObject(java.io.File f)` Reads a Serialized object, which may or may not be zipped.
`static java.lang.Object` | `readUnzippedObject(java.io.File f)` Reads a serialized object from a file.
`static java.io.File` | `uniqueFile(java.io.File dir, java.lang.String prefix, java.lang.String extension)` Creates a file, making sure that its name is unique.
`static void` | `writeGzippedObject(java.io.File f, java.io.Serializable obj)` Writes a serialized version of obj to a given file, compressing it using gzip.
`static void` | `writeObject(java.io.File f, java.io.Serializable obj)` Serializes an object to a file, masking out annoying exceptions.

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

Method Detail

### writeObject

    public static void writeObject(java.io.File f,
                                   java.io.Serializable obj)

  Serializes an object to a file, masking out annoying exceptions. Any IO exceptions are caught, and printed to standard error. Consider using `writeGzippedObject(java.io.File, java.io.Serializable)` instead, for that method will compress the serialized file, and it'll still be reaoable by `readObject(java.io.File)`.

  Parameters:
    `f` - File to write to
    `obj` - Object to serialize
  See Also:
    `writeGzippedObject(java.io.File, java.io.Serializable)`

### readObject

    public static java.lang.Object readObject(java.io.File f)

  Reads a Serialized object, which may or may not be zipped. Guesses from the file name whether to decompress or not.

  Parameters:
    `f` - File to read data from
  Returns:
    A deserialized object.

### readUnzippedObject

    public static java.lang.Object readUnzippedObject(java.io.File f)

  Reads a serialized object from a file. You probably want to use `readObject(java.io.File)` instead, because that method will automatically guess from the extension whether the file is compressed, and call this method if necessary.

  Parameters:
    `f` - File to read object from
  See Also:
    `readObject(java.io.File)`

### readFile

    public static java.lang.String[] readFile(java.io.File f)
                                       throws java.io.IOException

  Reads every line from a given text file.

  Parameters:
    `f` - Input file.
  Returns:
    String[] Array containing each line in `f`.
  Throws:
    `java.io.IOException`

### uniqueFile

    public static java.io.File uniqueFile(java.io.File dir,
                                          java.lang.String prefix,
                                          java.lang.String extension)
                                   throws java.io.IOException

  Creates a file, making sure that its name is unique. The file will be created as if by `new File(dir, prefix+i+extension)`, where i is an integer chosen such that the returned File does not exist.

  Parameters:
    `dir` - Directory to use for the returned file
    `prefix` - Prefix of the file name (before the uniquifying integer)
    `extension` - Suffix of the file name (after the uniquifying integer)
  Throws:
    `java.io.IOException`

### writeGzippedObject

    public static void writeGzippedObject(java.io.File f,
                                          java.io.Serializable obj)

  Writes a serialized version of obj to a given file, compressing it using gzip.

  Parameters:
    `f` - File to write to
    `obj` - Object to serialize

### readGzippedObject

    public static java.lang.Object readGzippedObject(java.io.File f)

  Reads a serialized object from a file that has been compressed using gzip. You probably want to use `readObject(java.io.File)` instead, because it will automatically guess from the extension whether the file is compressed, and call this method if necessary.

  Parameters:
    `f` - Compressed file to read object from
  See Also:
    `readObject(java.io.File)`

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