Package htsjdk.tribble.readers
Class AsciiLineReader
- java.lang.Object
-
- htsjdk.tribble.readers.AsciiLineReader
-
- All Implemented Interfaces:
LocationAware
,LineReader
,Closeable
,AutoCloseable
public class AsciiLineReader extends Object implements LineReader, LocationAware
A simple class that providesreadLine()
functionality around a PositionalBufferedStreamBufferedReader
and itsBufferedReader.readLine()
method should be used in preference to this class (when theLocationAware
functionality is not required) because it offers greater performance.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AsciiLineReader()
AsciiLineReader(PositionalBufferedStream is)
Deprecated.8/8/2017 usefrom(java.io.InputStream)
AsciiLineReader(InputStream is)
Deprecated.8/8/2017 usefrom(java.io.InputStream)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
static AsciiLineReader
from(InputStream inputStream)
Create an AsciiLineReader of the appropriate type for a given InputStream.int
getLineTerminatorLength()
Returns the length of the line terminator read after the last read line.long
getPosition()
The current offset, in bytes, of this stream/writer/file.String
readLine()
Same asreadLine(PositionalBufferedStream)
but uses the stream provided in the constructorString
readLine(PositionalBufferedStream stream)
Deprecated.8/8/2017 usefrom(java.io.InputStream)
to create a new AsciiLineReader andreadLine()
String
toString()
-
-
-
Constructor Detail
-
AsciiLineReader
protected AsciiLineReader()
-
AsciiLineReader
@Deprecated public AsciiLineReader(InputStream is)
Deprecated.8/8/2017 usefrom(java.io.InputStream)
Note: This class implements LocationAware, which requires preservation of virtual file pointers on BGZF inputs. However, if the inputStream wrapped by this class is a BlockCompressedInputStream, it violates that contract by wrapping the stream and returning positional file offsets instead.
-
AsciiLineReader
@Deprecated public AsciiLineReader(PositionalBufferedStream is)
Deprecated.8/8/2017 usefrom(java.io.InputStream)
- Parameters:
is
- thePositionalBufferedStream
input stream to be wrapped
-
-
Method Detail
-
from
public static AsciiLineReader from(InputStream inputStream)
Create an AsciiLineReader of the appropriate type for a given InputStream.- Parameters:
inputStream
- An InputStream-derived class that implements BlockCompressedInputStream or PositionalBufferedStream- Returns:
- AsciiLineReader that wraps inputStream
-
getPosition
public long getPosition()
Description copied from interface:LocationAware
The current offset, in bytes, of this stream/writer/file. Or, if this is an iterator/producer, the offset (in bytes) of the END of the most recently returned record (since a produced record corresponds to something that has been read already). See class javadoc for more. Note that for BGZF files, this does not represent an actually file position, but a virtual file pointer.- Specified by:
getPosition
in interfaceLocationAware
- Returns:
- The position of the InputStream
-
getLineTerminatorLength
public int getLineTerminatorLength()
Returns the length of the line terminator read after the last read line. Returns either: -1 if no line has been read 0 after the last line if the last line in the file had no CR or LF line ending 1 if the line ended with CR or LF 2 if the line ended with CR and LF
-
readLine
@Deprecated public String readLine(PositionalBufferedStream stream) throws IOException
Deprecated.8/8/2017 usefrom(java.io.InputStream)
to create a new AsciiLineReader andreadLine()
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.- Parameters:
stream
- the stream to read the next line from- Returns:
- A String containing the contents of the line or null if the end of the stream has been reached
- Throws:
IOException
-
readLine
public String readLine() throws IOException
Same asreadLine(PositionalBufferedStream)
but uses the stream provided in the constructor- Specified by:
readLine
in interfaceLineReader
- Returns:
- The next string, or null when input is exhausted.
- Throws:
IOException
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceLineReader
-
-