Class IOUtils


  • public class IOUtils
    extends java.lang.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

      Constructors 
      Constructor Description
      IOUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean closeEasy​(java.io.BufferedReader in)  
      static int copy​(java.io.InputStream in, java.io.OutputStream out)  
      static int copy​(java.io.Reader in, java.io.Writer out)  
      static java.lang.String getCharEncoding()  
      static java.io.BufferedReader getReader​(java.io.InputStream in)  
      static java.io.PrintWriter getWriter​(java.io.OutputStream out)  
      static java.util.Iterator<java.lang.String> lineIterator​(java.io.BufferedReader reader)  
      static java.util.Iterator<java.lang.String> lineIterator​(java.lang.String path)  
      static java.io.BufferedReader openIn​(java.io.File path)  
      static java.io.BufferedReader openIn​(java.lang.String path)  
      static java.io.BufferedReader openInHard​(java.io.File path)  
      static java.io.BufferedReader openInHard​(java.lang.String path)  
      static java.io.ObjectInputStream openObjIn​(java.io.File path)  
      static java.io.ObjectInputStream openObjIn​(java.lang.String path)  
      static java.io.ObjectOutputStream openObjOut​(java.io.File path)  
      static java.io.ObjectOutputStream openObjOut​(java.lang.String path)  
      static java.io.PrintWriter openOut​(java.io.File path)  
      static java.io.PrintWriter openOut​(java.lang.String path)  
      static java.io.PrintWriter openOutEasy​(java.io.File path)  
      static java.io.PrintWriter openOutEasy​(java.lang.String path)  
      static java.io.PrintWriter openOutHard​(java.io.File path)  
      static java.io.PrintWriter openOutHard​(java.lang.String path)  
      static java.lang.String readLine​(java.lang.String path)  
      static java.lang.String readLineEasy​(java.lang.String path)  
      static java.util.List<java.lang.String> readLines​(java.io.BufferedReader in)  
      static java.util.List<java.lang.String> readLines​(java.lang.String path)  
      static java.util.List<java.lang.String> readLinesEasy​(java.lang.String path)  
      static java.util.List<java.lang.String> readLinesHard​(java.lang.String path)  
      static java.lang.Object readObjFile​(java.io.File path)  
      static java.lang.Object readObjFile​(java.lang.String path)  
      static java.lang.Object readObjFileEasy​(java.io.File path)  
      static java.lang.Object readObjFileEasy​(java.lang.String path)  
      static java.lang.Object readObjFileHard​(java.io.File path)  
      static java.lang.Object readObjFileHard​(java.lang.String path)  
      static void setCharEncoding​(java.lang.String charEncoding)  
      static void writeObjFile​(java.io.File path, java.lang.Object obj)  
      static boolean writeObjFileEasy​(java.io.File path, java.lang.Object obj)  
      static void writeObjFileHard​(java.io.File path, java.lang.Object obj)  
      static void writeObjFileHard​(java.lang.String path, java.lang.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 java.io.BufferedReader openIn​(java.lang.String path)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • openIn

        public static java.io.BufferedReader openIn​(java.io.File path)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • openInHard

        public static java.io.BufferedReader openInHard​(java.lang.String path)
      • openInHard

        public static java.io.BufferedReader openInHard​(java.io.File path)
      • openOut

        public static java.io.PrintWriter openOut​(java.lang.String path)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • openOut

        public static java.io.PrintWriter openOut​(java.io.File path)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • openOutEasy

        public static java.io.PrintWriter openOutEasy​(java.lang.String path)
      • openOutEasy

        public static java.io.PrintWriter openOutEasy​(java.io.File path)
      • openOutHard

        public static java.io.PrintWriter openOutHard​(java.lang.String path)
      • openOutHard

        public static java.io.PrintWriter openOutHard​(java.io.File path)
      • openObjIn

        public static java.io.ObjectInputStream openObjIn​(java.lang.String path)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • openObjIn

        public static java.io.ObjectInputStream openObjIn​(java.io.File path)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • openObjOut

        public static java.io.ObjectOutputStream openObjOut​(java.lang.String path)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • openObjOut

        public static java.io.ObjectOutputStream openObjOut​(java.io.File path)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • readObjFile

        public static java.lang.Object readObjFile​(java.lang.String path)
                                            throws java.io.IOException,
                                                   java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readObjFile

        public static java.lang.Object readObjFile​(java.io.File path)
                                            throws java.io.IOException,
                                                   java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readObjFileEasy

        public static java.lang.Object readObjFileEasy​(java.lang.String path)
      • readObjFileEasy

        public static java.lang.Object readObjFileEasy​(java.io.File path)
      • readObjFileHard

        public static java.lang.Object readObjFileHard​(java.lang.String path)
      • readObjFileHard

        public static java.lang.Object readObjFileHard​(java.io.File path)
      • writeObjFile

        public static void writeObjFile​(java.io.File path,
                                        java.lang.Object obj)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeObjFileEasy

        public static boolean writeObjFileEasy​(java.io.File path,
                                               java.lang.Object obj)
      • writeObjFileHard

        public static void writeObjFileHard​(java.lang.String path,
                                            java.lang.Object obj)
      • writeObjFileHard

        public static void writeObjFileHard​(java.io.File path,
                                            java.lang.Object obj)
      • closeEasy

        public static boolean closeEasy​(java.io.BufferedReader in)
      • copy

        public static int copy​(java.io.InputStream in,
                               java.io.OutputStream out)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • copy

        public static int copy​(java.io.Reader in,
                               java.io.Writer out)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • lineIterator

        public static java.util.Iterator<java.lang.String> lineIterator​(java.lang.String path)
                                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • lineIterator

        public static java.util.Iterator<java.lang.String> lineIterator​(java.io.BufferedReader reader)
        Parameters:
        reader -
        Returns:
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.io.BufferedReader in)
                                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readLinesEasy

        public static java.util.List<java.lang.String> readLinesEasy​(java.lang.String path)
      • readLinesHard

        public static java.util.List<java.lang.String> readLinesHard​(java.lang.String path)
      • readLine

        public static java.lang.String readLine​(java.lang.String path)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readLineEasy

        public static java.lang.String readLineEasy​(java.lang.String path)
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.lang.String path)
                                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • getCharEncoding

        public static java.lang.String getCharEncoding()
      • setCharEncoding

        public static void setCharEncoding​(java.lang.String charEncoding)
      • getReader

        public static java.io.BufferedReader getReader​(java.io.InputStream in)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • getWriter

        public static java.io.PrintWriter getWriter​(java.io.OutputStream out)
                                             throws java.io.IOException
        Throws:
        java.io.IOException