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
public class SkipLinesInputStream extends BufferedInputStream
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
Fields Modifier and Type Field Description protected static int
DEFAULT_BUFFER_SIZE
protected static int
EOF
protected static int
LINE_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description SkipLinesInputStream(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 Type Method Description int
available()
int
getBufferSize()
static int
getDefaultBufferSize()
int
read()
int
read(byte[] b, int off, int len)
String
readLine()
Returns the next available line from the stream as String.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.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
DEFAULT_BUFFER_SIZE
protected static final int DEFAULT_BUFFER_SIZE- See Also:
- Constant Field Values
-
EOF
protected static final int EOF- See Also:
- Constant Field Values
-
LINE_BUFFER_SIZE
protected static final int LINE_BUFFER_SIZE- See Also:
- Constant Field Values
-
-
Constructor Details
-
SkipLinesInputStream
public SkipLinesInputStream(InputStream in, int skipHeaderLines, int skipFooterLines) throws IOExceptionCreates 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 IOExceptionCreates 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
-