Class EOLConvertingInputStream

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

    public class EOLConvertingInputStream
    extends java.io.InputStream
    InputStream which converts \r bytes not followed by \n and \n not preceded by \r to \r\n.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CONVERT_BOTH
      Converts single '\r' and '\n' to '\r\n'
      static int CONVERT_CR
      Converts single '\r' to '\r\n'
      static int CONVERT_LF
      Converts single '\n' to '\r\n'
      private int flags  
      private java.io.PushbackInputStream in  
      private int previous  
    • Constructor Summary

      Constructors 
      Constructor Description
      EOLConvertingInputStream​(java.io.InputStream in)
      Creates a new EOLConvertingInputStream instance converting bytes in the given InputStream.
      EOLConvertingInputStream​(java.io.InputStream in, int flags)
      Creates a new EOLConvertingInputStream instance converting bytes in the given InputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the underlying stream.
      int read()  
      • Methods inherited from class java.io.InputStream

        available, mark, 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

      • CONVERT_CR

        public static final int CONVERT_CR
        Converts single '\r' to '\r\n'
        See Also:
        Constant Field Values
      • CONVERT_LF

        public static final int CONVERT_LF
        Converts single '\n' to '\r\n'
        See Also:
        Constant Field Values
      • CONVERT_BOTH

        public static final int CONVERT_BOTH
        Converts single '\r' and '\n' to '\r\n'
        See Also:
        Constant Field Values
      • in

        private java.io.PushbackInputStream in
      • previous

        private int previous
      • flags

        private int flags
    • Constructor Detail

      • EOLConvertingInputStream

        public EOLConvertingInputStream​(java.io.InputStream in)
        Creates a new EOLConvertingInputStream instance converting bytes in the given InputStream. The flag CONVERT_BOTH is the default.
        Parameters:
        in - the InputStream to read from.
      • EOLConvertingInputStream

        public EOLConvertingInputStream​(java.io.InputStream in,
                                        int flags)
        Creates a new EOLConvertingInputStream instance converting bytes in the given InputStream.
        Parameters:
        in - the InputStream to read from.
        flags - one of CONVERT_CR, CONVERT_LF or CONVERT_BOTH.
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        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 - on I/O errors.
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
        See Also:
        InputStream.read()