Class IOUtils
java.lang.Object
org.biojava3.core.sequence.io.util.IOUtils
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Closure interface used when working withIOUtils#processReader(String)
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Closes any Object which implements the interfaceCloseable
and sending any error to the logger but not forcing any explicit catching of stream errors.static void
copy
(InputStream input, OutputStream output) Moves the bytes from input to output using a 4KB byte array.getGCGChecksum
(List<S> sequences) Calculates GCG checksum for entire list of sequencesgetGCGChecksum
(S sequence) Calculates GCG checksum for a given sequencegetGCGHeader
(List<S> sequences) Assembles a GCG file headergetGCGType
(CompoundSet<C> cs) Determines GCG typegetIDFormat
(List<S> sequences) Creates format String for accession IDsReturns the contents of a buffered reader as a list of stringsDelegates togetList(InputStream)
by wrapping the File in a valid stream.getList
(InputStream is) Delegates togetList(BufferedReader)
by wrapping the InputStream in a valid reader.static String
getPDBCharacter
(boolean web, char c1, char c2, boolean similar, char c) Creates formatted String for a single character of PDB outputstatic String
getPDBConservation
(boolean web, char c1, char c2, boolean similar) Creates formatted String for displaying conservation in PDB outputstatic String
Creates formatted String for displaying conservation legend in PDB outputstatic InputStream
For a filename this code will check the extension of the file for a .gz extension.static void
processReader
(BufferedReader br, IOUtils.ReaderProcessor processor) Takes in a reader and a processor, reads every line from the given file and then invokes the processor.
-
Constructor Details
-
IOUtils
public IOUtils()
-
-
Method Details
-
close
Closes any Object which implements the interfaceCloseable
and sending any error to the logger but not forcing any explicit catching of stream errors.- Parameters:
c
- The stream to close
-
copy
Moves the bytes from input to output using a 4KB byte array.- Parameters:
input
- Input stream of bytesoutput
- 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 processprocessor
- The processor to invoke on all lines- Throws:
ParserException
- Can throw this if we cannot parse the given reader
-
getList
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
Delegates togetList(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
Delegates togetList(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 usesopenFile(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:
ParserException
- Can throw this if the file is not a file or we cannot parse it
-
openFile
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 aGZIPInputStream
. Otherwise we return a normalFileInputStream
.- Parameters:
file
- File which may or may not be GZipped- Returns:
- The final stream
- Throws:
ParserException
- Can throw this if the file is not a file or we cannot open it for processing
-
getGCGChecksum
Calculates GCG checksum for entire list of sequences- Parameters:
sequences
- list of sequences- Returns:
- GCG checksum
-
getGCGChecksum
Calculates GCG checksum for a given sequence- Parameters:
sequence
- given sequence- Returns:
- GCG checksum
-
getGCGHeader
Assembles a GCG file header- Parameters:
sequences
- list of sequences- Returns:
- GCG header
-
getGCGType
Determines GCG type- Parameters:
cs
- compound set of sequences- Returns:
- GCG type
-
getIDFormat
Creates format String for accession IDs- Parameters:
sequences
- list of sequences- Returns:
- format String for accession IDs
-
getPDBCharacter
Creates formatted String for a single character of PDB output- Parameters:
web
- true for HTML displayc1
- character in first sequencec2
- character in second sequencesimilar
- true if c1 and c2 are considered similar compoundsc
- character to display- Returns:
- formatted String
-
getPDBConservation
Creates formatted String for displaying conservation in PDB output- Parameters:
web
- true for HTML displayc1
- character in first sequencec2
- character in second sequencesimilar
- true if c1 and c2 are considered similar compounds- Returns:
- formatted String
-
getPDBLegend
Creates formatted String for displaying conservation legend in PDB output- Returns:
- legend String
-