edu.berkeley.nlp.lm.io
Class IOUtils

java.lang.Object
  extended by edu.berkeley.nlp.lm.io.IOUtils

public class IOUtils
extends Object

Some IO utility functions. Naming convention: "Hard" means that the function throws a RuntimeException upon failure, "Easy" means it returns null.

Author:
adampauls, Percy Liang

Constructor Summary
IOUtils()
           
 
Method Summary
static boolean closeEasy(BufferedReader in)
           
static int copy(InputStream in, OutputStream out)
           
static int copy(Reader in, Writer out)
           
static String getCharEncoding()
           
static BufferedReader getReader(InputStream in)
           
static PrintWriter getWriter(OutputStream out)
           
static Iterator<String> lineIterator(BufferedReader reader)
           
static Iterator<String> lineIterator(String path)
           
static BufferedReader openIn(File path)
           
static BufferedReader openIn(String path)
           
static BufferedReader openInHard(File path)
           
static BufferedReader openInHard(String path)
           
static ObjectInputStream openObjIn(File path)
           
static ObjectInputStream openObjIn(String path)
           
static ObjectOutputStream openObjOut(File path)
           
static ObjectOutputStream openObjOut(String path)
           
static PrintWriter openOut(File path)
           
static PrintWriter openOut(String path)
           
static PrintWriter openOutEasy(File path)
           
static PrintWriter openOutEasy(String path)
           
static PrintWriter openOutHard(File path)
           
static PrintWriter openOutHard(String path)
           
static String readLine(String path)
           
static String readLineEasy(String path)
           
static List<String> readLines(BufferedReader in)
           
static List<String> readLines(String path)
           
static List<String> readLinesEasy(String path)
           
static List<String> readLinesHard(String path)
           
static Object readObjFile(File path)
           
static Object readObjFile(String path)
           
static Object readObjFileEasy(File path)
           
static Object readObjFileEasy(String path)
           
static Object readObjFileHard(File path)
           
static Object readObjFileHard(String path)
           
static void setCharEncoding(String charEncoding)
           
static void writeObjFile(File path, Object obj)
           
static boolean writeObjFileEasy(File path, Object obj)
           
static void writeObjFileHard(File path, Object obj)
           
static void writeObjFileHard(String path, Object obj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOUtils

public IOUtils()
Method Detail

openIn

public static BufferedReader openIn(String path)
                             throws IOException
Throws:
IOException

openIn

public static BufferedReader openIn(File path)
                             throws IOException
Throws:
IOException

openInHard

public static BufferedReader openInHard(String path)

openInHard

public static BufferedReader openInHard(File path)

openOut

public static PrintWriter openOut(String path)
                           throws IOException
Throws:
IOException

openOut

public static PrintWriter openOut(File path)
                           throws IOException
Throws:
IOException

openOutEasy

public static PrintWriter openOutEasy(String path)

openOutEasy

public static PrintWriter openOutEasy(File path)

openOutHard

public static PrintWriter openOutHard(String path)

openOutHard

public static PrintWriter openOutHard(File path)

openObjIn

public static ObjectInputStream openObjIn(String path)
                                   throws IOException
Throws:
IOException

openObjIn

public static ObjectInputStream openObjIn(File path)
                                   throws IOException
Throws:
IOException

openObjOut

public static ObjectOutputStream openObjOut(String path)
                                     throws IOException
Throws:
IOException

openObjOut

public static ObjectOutputStream openObjOut(File path)
                                     throws IOException
Throws:
IOException

readObjFile

public static Object readObjFile(String path)
                          throws IOException,
                                 ClassNotFoundException
Throws:
IOException
ClassNotFoundException

readObjFile

public static Object readObjFile(File path)
                          throws IOException,
                                 ClassNotFoundException
Throws:
IOException
ClassNotFoundException

readObjFileEasy

public static Object readObjFileEasy(String path)

readObjFileEasy

public static Object readObjFileEasy(File path)

readObjFileHard

public static Object readObjFileHard(String path)

readObjFileHard

public static Object readObjFileHard(File path)

writeObjFile

public static void writeObjFile(File path,
                                Object obj)
                         throws IOException
Throws:
IOException

writeObjFileEasy

public static boolean writeObjFileEasy(File path,
                                       Object obj)

writeObjFileHard

public static void writeObjFileHard(String path,
                                    Object obj)

writeObjFileHard

public static void writeObjFileHard(File path,
                                    Object obj)

closeEasy

public static boolean closeEasy(BufferedReader in)

copy

public static int copy(InputStream in,
                       OutputStream out)
                throws IOException
Throws:
IOException

copy

public static int copy(Reader in,
                       Writer out)
                throws IOException
Throws:
IOException

lineIterator

public static Iterator<String> lineIterator(String path)
                                     throws IOException
Throws:
IOException

lineIterator

public static Iterator<String> lineIterator(BufferedReader reader)
Parameters:
reader -
Returns:

readLines

public static List<String> readLines(BufferedReader in)
                              throws IOException
Throws:
IOException

readLinesEasy

public static List<String> readLinesEasy(String path)

readLinesHard

public static List<String> readLinesHard(String path)

readLine

public static String readLine(String path)
                       throws IOException
Throws:
IOException

readLineEasy

public static String readLineEasy(String path)

readLines

public static List<String> readLines(String path)
                              throws IOException
Throws:
IOException

getCharEncoding

public static String getCharEncoding()

setCharEncoding

public static void setCharEncoding(String charEncoding)

getReader

public static BufferedReader getReader(InputStream in)
                                throws IOException
Throws:
IOException

getWriter

public static PrintWriter getWriter(OutputStream out)
                             throws IOException
Throws:
IOException