Package com.illumon.iris.importers.util
Class SkipLinesInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
com.illumon.iris.importers.util.SkipLinesInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
SkipLinesInputStream adds functionality to another InputStream namely the ability to skip header or footer lines.
The class maintains a queue of up to skip footer lines, popping a line on request only if there is more data to be
read in the input stream. The logic is only used if skip footer lines has a value greater than 0.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
protected static final int
protected static final int
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionSkipLinesInputStream
(InputStream in, int skipHeaderLines, int skipFooterLines) Creates SkipLinesInputStream wrapper around given InputStream.SkipLinesInputStream
(InputStream in, int skipHeaderLines, int skipFooterLines, int bufferSize) Creates SkipLinesInputStream wrapper around given InputStream using specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionint
int
static int
int
read()
int
read
(byte[] b, int off, int len) readLine()
Returns the next available line from the stream as String.readLine
(boolean ignoreLineBreakCharacters) If the ignoreLineBreakCharacters parameter is true the next available line will be returned without CR or LF or CRLF characters.protected void
readLineAsBytes
(gnu.trove.list.array.TByteArrayList line) Returns the next available line from the stream as bytes populated in TByteArrayList.void
reset()
long
skip
(long n) Methods inherited from class java.io.BufferedInputStream
close, mark, markSupported
Methods inherited from class java.io.FilterInputStream
read
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
DEFAULT_BUFFER_SIZE
protected static final int DEFAULT_BUFFER_SIZE- See Also:
-
EOF
protected static final int EOF- See Also:
-
LINE_BUFFER_SIZE
protected static final int LINE_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
SkipLinesInputStream
public SkipLinesInputStream(InputStream in, int skipHeaderLines, int skipFooterLines) throws IOException Creates SkipLinesInputStream wrapper around given InputStream.- Parameters:
in
- The underlying InputStreamskipHeaderLines
- Number of lines to skip at the beginningskipFooterLines
- Number of line to skip from end of stream- Throws:
IOException
-
SkipLinesInputStream
public SkipLinesInputStream(InputStream in, int skipHeaderLines, int skipFooterLines, int bufferSize) throws IOException Creates SkipLinesInputStream wrapper around given InputStream using specified buffer size.- Parameters:
in
- The underlying InputStreamskipHeaderLines
- Number of lines to skip at the beginningskipFooterLines
- Number of line to skip from end of streambufferSize
- BufferSize used by parent BufferedInputStream- Throws:
IOException
-
-
Method Details
-
getBufferSize
public int getBufferSize() -
getDefaultBufferSize
public static int getDefaultBufferSize() -
read
- Overrides:
read
in classBufferedInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classBufferedInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classBufferedInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classBufferedInputStream
- Throws:
IOException
-
reset
- Overrides:
reset
in classBufferedInputStream
- Throws:
IOException
-
readLine
If the ignoreLineBreakCharacters parameter is true the next available line will be returned without CR or LF or CRLF characters. If ignoreLineBreakCharacters parameter is false returns the next available line from the stream as String. A line is determined by CR, LF or CRLF. In case of a CR the next byte is looked up and if it is LF then returned line includes up to LF, otherwise up to CR. The next byte is then the first byte to be read next.- Parameters:
ignoreLineBreakCharacters
- indicates if the returned String should include the CR / LF or CRLF characters- Throws:
IOException
-
readLine
Returns the next available line from the stream as String. A line is determined by CR, LF or CRLF. In case of a CR the next byte is looked up and if it is LF then returned line includes up to LF, otherwise up to CR. The next byte is then the first byte to be read next.- Throws:
IOException
-
readLineAsBytes
Returns the next available line from the stream as bytes populated in TByteArrayList. A line is determined by CR, LF or CRLF. In case of a CR the next byte is looked up and if it is LF then returned line includes up to LF, otherwise up to CR. The next byte is then the first byte to be read next.- Parameters:
line
- TByteArrayList that holds the byte array of the next line.- Throws:
IOException
-