Class IOUtils


  • public class IOUtils
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  IOUtils.ReaderProcessor
      Closure interface used when working with IOUtils#processReader(String).
    • Constructor Summary

      Constructors 
      Constructor Description
      IOUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void close​(java.io.Closeable c)
      Closes any Object which implements the interface Closeable and sending any error to the logger but not forcing any explicit catching of stream errors.
      static void copy​(java.io.InputStream input, java.io.OutputStream output)
      Moves the bytes from input to output using a 4KB byte array.
      static <S extends Sequence<C>,​C extends Compound>
      int
      getGCGChecksum​(java.util.List<S> sequences)
      Calculates GCG checksum for entire list of sequences
      static <S extends Sequence<C>,​C extends Compound>
      int
      getGCGChecksum​(S sequence)
      Calculates GCG checksum for a given sequence
      static <S extends Sequence<C>,​C extends Compound>
      java.lang.String
      getGCGHeader​(java.util.List<S> sequences)
      Assembles a GCG file header
      static <C extends Compound>
      java.lang.String
      getGCGType​(CompoundSet<C> cs)
      Determines GCG type
      static <S extends Sequence<C>,​C extends Compound>
      java.lang.String
      getIDFormat​(java.util.List<S> sequences)
      Creates format String for accession IDs
      static java.util.List<java.lang.String> getList​(java.io.BufferedReader br)
      Returns the contents of a buffered reader as a list of strings
      static java.util.List<java.lang.String> getList​(java.io.File file)
      Delegates to getList(InputStream) by wrapping the File in a valid stream.
      static java.util.List<java.lang.String> getList​(java.io.InputStream is)
      Delegates to getList(BufferedReader) by wrapping the InputStream in a valid reader.
      static java.lang.String getPDBCharacter​(boolean web, char c1, char c2, boolean similar, char c)
      Creates formatted String for a single character of PDB output
      static java.lang.String getPDBConservation​(boolean web, char c1, char c2, boolean similar)
      Creates formatted String for displaying conservation in PDB output
      static java.lang.String getPDBLegend()
      Creates formatted String for displaying conservation legend in PDB output
      static java.io.InputStream openFile​(java.io.File file)
      For a filename this code will check the extension of the file for a .gz extension.
      static void print​(java.lang.String string, java.io.File file)
      Prints string to file.
      static void processReader​(java.io.BufferedReader br, IOUtils.ReaderProcessor processor)
      Takes in a reader and a processor, reads every line from the given file and then invokes the processor.
      • 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

      • close

        public static void close​(java.io.Closeable c)
        Closes any Object which implements the interface Closeable and sending any error to the logger but not forcing any explicit catching of stream errors.
        Parameters:
        c - The stream to close
      • copy

        public static void copy​(java.io.InputStream input,
                                java.io.OutputStream output)
                         throws java.io.IOException
        Moves the bytes from input to output using a 4KB byte array.
        Parameters:
        input - Input stream of bytes
        output - Output stream of bytes
        Throws:
        java.io.IOException - If anything occurs in the case of the reads and writes
      • processReader

        public static void processReader​(java.io.BufferedReader br,
                                         IOUtils.ReaderProcessor processor)
                                  throws ParserException
        Takes in a reader and a processor, reads every line from the given file and then invokes the processor. What you do with the lines is dependent on your processor. The code will automatically close the given BufferedReader.
        Parameters:
        br - The reader to process
        processor - The processor to invoke on all lines
        Throws:
        ParserException - Can throw this if we cannot parse the given reader
      • getList

        public static java.util.List<java.lang.String> getList​(java.io.BufferedReader br)
                                                        throws ParserException
        Returns the contents of a buffered reader as a list of strings
        Parameters:
        br - BufferedReader to read from; will be closed
        Returns:
        List of Strings
        Throws:
        ParserException - Can throw this if we cannot parse the given reader
      • getList

        public static java.util.List<java.lang.String> getList​(java.io.InputStream is)
                                                        throws ParserException
        Delegates to getList(BufferedReader) by wrapping the InputStream in a valid reader. No encoding is mentioned so if you need anything more advanced then use the other version of this method.
        Parameters:
        is - InputStream which is a text file
        Returns:
        List of Strings representing the lines of the files
        Throws:
        ParserException - Can throw this if the file is not a file or we cannot parse it
      • getList

        public static java.util.List<java.lang.String> getList​(java.io.File file)
                                                        throws java.io.IOException
        Delegates to getList(InputStream) by wrapping the File in a valid stream. No encoding is mentioned so if you need anything more advanced then use the other version of this method. Since this uses openFile(File) this code can support GZipped and plain files.
        Parameters:
        file - File which is a text file
        Returns:
        List of Strings representing the lines of the files
        Throws:
        java.io.IOException
      • openFile

        public static java.io.InputStream openFile​(java.io.File file)
                                            throws java.io.IOException
        For a filename this code will check the extension of the file for a .gz extension. If it finds one then the InputStream given back is a GZIPInputStream. Otherwise we return a normal FileInputStream.
        Parameters:
        file - File which may or may not be GZipped
        Returns:
        The final stream
        Throws:
        IOExceptio - n
        java.io.IOException
      • getGCGChecksum

        public static <S extends Sequence<C>,​C extends Compound> int getGCGChecksum​(java.util.List<S> sequences)
        Calculates GCG checksum for entire list of sequences
        Parameters:
        sequences - list of sequences
        Returns:
        GCG checksum
      • getGCGChecksum

        public static <S extends Sequence<C>,​C extends Compound> int getGCGChecksum​(S sequence)
        Calculates GCG checksum for a given sequence
        Parameters:
        sequence - given sequence
        Returns:
        GCG checksum
      • getGCGHeader

        public static <S extends Sequence<C>,​C extends Compound> java.lang.String getGCGHeader​(java.util.List<S> sequences)
        Assembles a GCG file header
        Parameters:
        sequences - list of sequences
        Returns:
        GCG header
      • getGCGType

        public static <C extends Compound> java.lang.String getGCGType​(CompoundSet<C> cs)
        Determines GCG type
        Parameters:
        cs - compound set of sequences
        Returns:
        GCG type
      • getIDFormat

        public static <S extends Sequence<C>,​C extends Compound> java.lang.String getIDFormat​(java.util.List<S> sequences)
        Creates format String for accession IDs
        Parameters:
        sequences - list of sequences
        Returns:
        format String for accession IDs
      • getPDBCharacter

        public static java.lang.String getPDBCharacter​(boolean web,
                                                       char c1,
                                                       char c2,
                                                       boolean similar,
                                                       char c)
        Creates formatted String for a single character of PDB output
        Parameters:
        web - true for HTML display
        c1 - character in first sequence
        c2 - character in second sequence
        similar - true if c1 and c2 are considered similar compounds
        c - character to display
        Returns:
        formatted String
      • getPDBConservation

        public static java.lang.String getPDBConservation​(boolean web,
                                                          char c1,
                                                          char c2,
                                                          boolean similar)
        Creates formatted String for displaying conservation in PDB output
        Parameters:
        web - true for HTML display
        c1 - character in first sequence
        c2 - character in second sequence
        similar - true if c1 and c2 are considered similar compounds
        Returns:
        formatted String
      • getPDBLegend

        public static java.lang.String getPDBLegend()
        Creates formatted String for displaying conservation legend in PDB output
        Returns:
        legend String
      • print

        public static void print​(java.lang.String string,
                                 java.io.File file)
                          throws java.io.IOException
        Prints string to file.
        Throws:
        java.io.IOException - If any I/O exception occurs while printing; this method does not catch any exceptions