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.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AutoLFInputStream.IsBinaryException
A special exception thrown whenAutoLFInputStream
is told to throw an exception when attempting to read a binary file.static class
AutoLFInputStream.StreamFlag
Flags for controlling auto-detection of binary vs.
-
Field Summary
Fields Modifier and Type Field Description private boolean
abortIfBinary
private byte[]
buf
private int
cnt
private boolean
detectBinary
private boolean
forCheckout
private java.io.InputStream
in
private boolean
isBinary
Set totrue
if the input was detected to be binary data.private boolean
passAsIs
Set totrue
if no CR/LF processing is to be done: if the input is binary data, or CR/LF-delimited text andAutoLFInputStream.StreamFlag.FOR_CHECKOUT
was given.private int
ptr
private 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 void
close()
static AutoLFInputStream
create(java.io.InputStream in, AutoLFInputStream.StreamFlag... flags)
Factory method for creating anAutoLFInputStream
with the specifiedflags
.private boolean
fillBuffer()
boolean
isBinary()
Whether the stream has detected as a binary so far.int
read()
int
read(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 totrue
if no CR/LF processing is to be done: if the input is binary data, or CR/LF-delimited text andAutoLFInputStream.StreamFlag.FOR_CHECKOUT
was given.
-
isBinary
private boolean isBinary
Set totrue
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 streamflags
-AutoLFInputStream.StreamFlag
s 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, 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 anAutoLFInputStream
with the specifiedflags
.- Parameters:
in
- raw input streamflags
-AutoLFInputStream.StreamFlag
s controlling the stream behavior- Returns:
- a new
AutoLFInputStream
- Since:
- 5.9
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] bs, int off, int len) throws java.io.IOException
- Overrides:
read
in 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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
fillBuffer
private boolean fillBuffer() throws java.io.IOException
- Throws:
java.io.IOException
-
-