Package org.eclipse.jgit.util.io
Class AutoLFInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.eclipse.jgit.util.io.AutoLFInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class AutoLFInputStream extends java.io.InputStreamAn 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAutoLFInputStream.IsBinaryExceptionA special exception thrown whenAutoLFInputStreamis told to throw an exception when attempting to read a binary file.static classAutoLFInputStream.StreamFlagFlags for controlling auto-detection of binary vs.
-
Field Summary
Fields Modifier and Type Field Description private booleanabortIfBinaryprivate byte[]bufprivate intcntprivate booleandetectBinaryprivate booleanforCheckoutprivate java.io.InputStreaminprivate booleanisBinarySet totrueif the input was detected to be binary data.private booleanpassAsIsSet totrueif no CR/LF processing is to be done: if the input is binary data, or CR/LF-delimited text andAutoLFInputStream.StreamFlag.FOR_CHECKOUTwas given.private intptrprivate byte[]single
-
Constructor Summary
Constructors Constructor Description AutoLFInputStream(java.io.InputStream in, boolean detectBinary)Deprecated.since 5.9, usecreate(InputStream, StreamFlag...)insteadAutoLFInputStream(java.io.InputStream in, boolean detectBinary, boolean abortIfBinary)Deprecated.since 5.9, usecreate(InputStream, StreamFlag...)insteadAutoLFInputStream(java.io.InputStream in, java.util.Set<AutoLFInputStream.StreamFlag> flags)Creates a new InputStream, wrapping the specified stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static AutoLFInputStreamcreate(java.io.InputStream in, AutoLFInputStream.StreamFlag... flags)Factory method for creating anAutoLFInputStreamwith the specifiedflags.private booleanfillBuffer()booleanisBinary()Whether the stream has detected as a binary so far.intread()intread(byte[] bs, int off, int len)
-
-
-
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
-
passAsIs
private boolean passAsIs
Set totrueif no CR/LF processing is to be done: if the input is binary data, or CR/LF-delimited text andAutoLFInputStream.StreamFlag.FOR_CHECKOUTwas given.
-
isBinary
private boolean isBinary
Set totrueif 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 streamflags-AutoLFInputStream.StreamFlags controlling the stream behavior;nullis treated as an empty set- Since:
- 5.9
-
AutoLFInputStream
@Deprecated public AutoLFInputStream(java.io.InputStream in, boolean detectBinary)Deprecated.since 5.9, usecreate(InputStream, StreamFlag...)insteadCreates a new InputStream, wrapping the specified stream.- Parameters:
in- raw input streamdetectBinary- whether binaries should be detected- Since:
- 2.0
-
AutoLFInputStream
@Deprecated public AutoLFInputStream(java.io.InputStream in, boolean detectBinary, boolean abortIfBinary)Deprecated.since 5.9, usecreate(InputStream, StreamFlag...)insteadCreates a new InputStream, wrapping the specified stream.- Parameters:
in- raw input streamdetectBinary- whether binaries should be detectedabortIfBinary- throw an IOException if the file is binary- Since:
- 3.3
-
-
Method Detail
-
create
public static AutoLFInputStream create(java.io.InputStream in, AutoLFInputStream.StreamFlag... flags)
Factory method for creating anAutoLFInputStreamwith the specifiedflags.- Parameters:
in- raw input streamflags-AutoLFInputStream.StreamFlags controlling the stream behavior- Returns:
- a new
AutoLFInputStream - Since:
- 5.9
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] bs, int off, int len) throws java.io.IOException- Overrides:
readin classjava.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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
fillBuffer
private boolean fillBuffer() throws java.io.IOException- Throws:
java.io.IOException
-
-