Class AutoLFInputStream

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

    public class AutoLFInputStream
    extends java.io.InputStream
    An InputStream that normalizes CRLF to LF.

    Existing single CR are not changed to LF but are retained as is.

    Optionally, a binary check on the first 8kB is performed and in case of binary files, canonicalization is turned off (for the complete file). If binary checking determines that the input is CR/LF-delimited text and the stream has been created for checkout, canonicalization is also turned off.

    Since:
    4.3
    • Field Detail

      • single

        private final byte[] single
      • buf

        private final byte[] buf
      • in

        private final java.io.InputStream in
      • cnt

        private int cnt
      • ptr

        private int ptr
      • isBinary

        private boolean isBinary
        Set to true if the input was detected to be binary data.
      • detectBinary

        private boolean detectBinary
      • abortIfBinary

        private final boolean abortIfBinary
      • forCheckout

        private final boolean forCheckout
    • Constructor Detail

      • AutoLFInputStream

        public AutoLFInputStream​(java.io.InputStream in,
                                 java.util.Set<AutoLFInputStream.StreamFlag> flags)
        Creates a new InputStream, wrapping the specified stream.
        Parameters:
        in - raw input stream
        flags - AutoLFInputStream.StreamFlags controlling the stream behavior; null is treated as an empty set
        Since:
        5.9
      • AutoLFInputStream

        @Deprecated
        public AutoLFInputStream​(java.io.InputStream in,
                                 boolean detectBinary)
        Deprecated.
        since 5.9, use create(InputStream, StreamFlag...) instead
        Creates a new InputStream, wrapping the specified stream.
        Parameters:
        in - raw input stream
        detectBinary - whether binaries should be detected
        Since:
        2.0
      • AutoLFInputStream

        @Deprecated
        public AutoLFInputStream​(java.io.InputStream in,
                                 boolean detectBinary,
                                 boolean abortIfBinary)
        Deprecated.
        since 5.9, use create(InputStream, StreamFlag...) instead
        Creates a new InputStream, wrapping the specified stream.
        Parameters:
        in - raw input stream
        detectBinary - whether binaries should be detected
        abortIfBinary - throw an IOException if the file is binary
        Since:
        3.3
    • Method Detail

      • read

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

        public int read​(byte[] bs,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • isBinary

        public boolean isBinary()
        Whether the stream has detected as a binary so far.
        Returns:
        true if the stream has detected as a binary so far.
        Since:
        3.3
      • close

        public void close()
                   throws java.io.IOException
        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
      • fillBuffer

        private boolean fillBuffer()
                            throws java.io.IOException
        Throws:
        java.io.IOException