Class IOUtils

    • Constructor Detail

    • Method Detail

      • close

        public static void close​(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​(InputStream input,
                                OutputStream output)
                         throws 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:
        IOException - If anything occurs in the case of the reads and writes
      • processReader

        public static void processReader​(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 List<StringgetList​(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 List<StringgetList​(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 List<StringgetList​(File file)
                                    throws 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:
        IOException
      • openFile

        public static InputStream openFile​(File file)
                                    throws 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
        IOException
      • getGCGChecksum

        public static <S extends Sequence<C>,​C extends Compound> int getGCGChecksum​(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 CompoundString getGCGHeader​(List<S> sequences)
        Assembles a GCG file header
        Parameters:
        sequences - list of sequences
        Returns:
        GCG header
      • getIDFormat

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

        public static 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 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 String getPDBLegend()
        Creates formatted String for displaying conservation legend in PDB output
        Returns:
        legend String
      • print

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