edu.stanford.nlp.io
Class IOUtils

java.lang.Object
  extended by edu.stanford.nlp.io.IOUtils

public class IOUtils
extends Object

Helper Class for storing serialized objects to disk.

Author:
Kayur Patel, Teg Grenager

Method Summary
static int lineCount(File textFile)
           
static Object readObjectFromFile(File file)
          Read an object from a stored file.
static Object readObjectFromFile(String filename)
          Read an object from a stored file.
static Object readObjectFromFileNoExceptions(File file)
          Read an object from a stored file without throwing exceptions.
static BufferedReader readReaderFromString(String textFileOrUrl)
           
static BufferedReader readReaderFromString(String textFileOrUrl, String encoding)
           
static ObjectInputStream readStreamFromString(String filenameOrUrl)
           
static File writeObjectToFile(Object o, File file)
          Write an object to a specified File.
static File writeObjectToFile(Object o, String filename)
          Write object to a file with the specified name.
static File writeObjectToFileNoExceptions(Object o, String filename)
          Write object to a file with the specified name.
static File writeObjectToTempFile(Object o, String filename)
          Write object to temp file which is destroyed when the program exits.
static File writeObjectToTempFileNoExceptions(Object o, String filename)
          Write object to a temp file and ignore exceptions.
static ObjectOutputStream writeStreamFromString(String serializePath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeObjectToFile

public static File writeObjectToFile(Object o,
                                     String filename)
                              throws IOException
Write object to a file with the specified name.

Parameters:
o - object to be written to file
filename - name of the temp file
Returns:
File containing the object
Throws:
IOException - If can't write file.

writeObjectToFile

public static File writeObjectToFile(Object o,
                                     File file)
                              throws IOException
Write an object to a specified File.

Parameters:
o - object to be written to file
file - The temp File
Returns:
File containing the object
Throws:
IOException - If File cannot be written

writeObjectToFileNoExceptions

public static File writeObjectToFileNoExceptions(Object o,
                                                 String filename)
Write object to a file with the specified name.

Parameters:
o - object to be written to file
filename - name of the temp file
Returns:
File containing the object, or null if an exception was caught

writeObjectToTempFile

public static File writeObjectToTempFile(Object o,
                                         String filename)
                                  throws IOException
Write object to temp file which is destroyed when the program exits.

Parameters:
o - object to be written to file
filename - name of the temp file
Returns:
File containing the object
Throws:
IOException - If file cannot be written

writeObjectToTempFileNoExceptions

public static File writeObjectToTempFileNoExceptions(Object o,
                                                     String filename)
Write object to a temp file and ignore exceptions.

Parameters:
o - object to be written to file
filename - name of the temp file
Returns:
File containing the object

readObjectFromFile

public static Object readObjectFromFile(File file)
                                 throws IOException,
                                        ClassNotFoundException
Read an object from a stored file.

Parameters:
file - the file pointing to the object to be retrived
Returns:
the object read from the file.
Throws:
IOException - If file cannot be read
ClassNotFoundException - If reading serialized object fails

readObjectFromFile

public static Object readObjectFromFile(String filename)
                                 throws IOException,
                                        ClassNotFoundException
Read an object from a stored file.

Parameters:
filename - The filename of the object to be retrived
Returns:
The object read from the file.
Throws:
IOException - If file cannot be read
ClassNotFoundException - If reading serialized object fails

readObjectFromFileNoExceptions

public static Object readObjectFromFileNoExceptions(File file)
Read an object from a stored file without throwing exceptions.

Parameters:
file - the file pointing to the object to be retrived
Returns:
the object read from the file, or null if an exception occurred.

lineCount

public static int lineCount(File textFile)
                     throws IOException
Throws:
IOException

writeStreamFromString

public static ObjectOutputStream writeStreamFromString(String serializePath)
                                                throws IOException
Throws:
IOException

readStreamFromString

public static ObjectInputStream readStreamFromString(String filenameOrUrl)
                                              throws IOException
Throws:
IOException

readReaderFromString

public static BufferedReader readReaderFromString(String textFileOrUrl)
                                           throws IOException
Throws:
IOException

readReaderFromString

public static BufferedReader readReaderFromString(String textFileOrUrl,
                                                  String encoding)
                                           throws IOException
Throws:
IOException


Stanford NLP Group