Class UnixLineEndingInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class UnixLineEndingInputStream
    extends java.io.InputStream
    A filtering input stream that ensures the content will have unix-style line endings, LF.
    Since:
    2.5
    • Constructor Summary

      Constructors 
      Constructor Description
      UnixLineEndingInputStream​(java.io.InputStream in, boolean ensureLineFeedAtEndOfFile)
      Create an input stream that filters another stream
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the stream.
      private int eofGame​(boolean previousWasSlashR)
      Handles the eof-handling at the end of the stream
      void mark​(int readlimit)
      int read()
      private int readWithUpdate()
      Reads the next item from the target, updating internal flags in the process
      • Methods inherited from class java.io.InputStream

        available, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • slashNSeen

        private boolean slashNSeen
      • slashRSeen

        private boolean slashRSeen
      • eofSeen

        private boolean eofSeen
      • target

        private final java.io.InputStream target
      • ensureLineFeedAtEndOfFile

        private final boolean ensureLineFeedAtEndOfFile
    • Constructor Detail

      • UnixLineEndingInputStream

        public UnixLineEndingInputStream​(java.io.InputStream in,
                                         boolean ensureLineFeedAtEndOfFile)
        Create 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 Detail

      • readWithUpdate

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

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.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 java.io.IOException
        Closes the stream. Also closes the underlying stream.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException - upon error
      • mark

        public void mark​(int readlimit)
        Overrides:
        mark in class java.io.InputStream