Class 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 Details

  • Constructor Details

    • SkipLinesInputStream

      public SkipLinesInputStream(InputStream in, int skipHeaderLines, int skipFooterLines) throws IOException
      Creates SkipLinesInputStream wrapper around given InputStream.
      Parameters:
      in - The underlying InputStream
      skipHeaderLines - Number of lines to skip at the beginning
      skipFooterLines - 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 InputStream
      skipHeaderLines - Number of lines to skip at the beginning
      skipFooterLines - Number of line to skip from end of stream
      bufferSize - BufferSize used by parent BufferedInputStream
      Throws:
      IOException
  • Method Details

    • getBufferSize

      public int getBufferSize()
    • getDefaultBufferSize

      public static int getDefaultBufferSize()
    • read

      public int read() throws IOException
      Overrides:
      read in class BufferedInputStream
      Throws:
      IOException
    • read

      public int read(@NotNull byte[] b, int off, int len) throws IOException
      Overrides:
      read in class BufferedInputStream
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Overrides:
      skip in class BufferedInputStream
      Throws:
      IOException
    • available

      public int available() throws IOException
      Overrides:
      available in class BufferedInputStream
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class BufferedInputStream
      Throws:
      IOException
    • readLine

      public String readLine(boolean ignoreLineBreakCharacters) throws IOException
      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

      public String readLine() throws IOException
      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

      protected void readLineAsBytes(gnu.trove.list.array.TByteArrayList line) throws IOException
      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