Class UnixLineEndingInputStream

java.lang.Object
java.io.InputStream
org.apache.commons.io.input.UnixLineEndingInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class UnixLineEndingInputStream extends InputStream
A filtering input stream that ensures the content will have UNIX-style line endings, LF.
Since:
2.5
  • Field Details

    • slashNSeen

      private boolean slashNSeen
    • slashRSeen

      private boolean slashRSeen
    • eofSeen

      private boolean eofSeen
    • target

      private final InputStream target
    • ensureLineFeedAtEndOfFile

      private final boolean ensureLineFeedAtEndOfFile
  • Constructor Details

    • UnixLineEndingInputStream

      public UnixLineEndingInputStream(InputStream in, boolean ensureLineFeedAtEndOfFile)
      Creates an input stream that filters another stream
      Parameters:
      in - The input stream to wrap
      ensureLineFeedAtEndOfFile - true to ensure that the file ends with LF
  • Method Details

    • readWithUpdate

      private int readWithUpdate() throws IOException
      Reads the next item from the target, updating internal flags in the process
      Returns:
      the next int read from the target stream
      Throws:
      IOException - upon error
    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • eofGame

      private int eofGame(boolean previousWasSlashR)
      Handles the EOF-handling at the end of the stream
      Parameters:
      previousWasSlashR - Indicates if the last seen was a \r
      Returns:
      The next char to output to the stream
    • close

      public void close() throws IOException
      Closes the stream. Also closes the underlying stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException - upon error
    • mark

      public void mark(int readlimit)
      Overrides:
      mark in class InputStream