Package org.apache.commons.io.input
Class UnixLineEndingInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.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
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
atEos
private boolean
atSlashCr
private boolean
atSlashLf
private java.io.InputStream
in
private boolean
lineFeedAtEndOfFile
-
Constructor Summary
Constructors Constructor Description UnixLineEndingInputStream(java.io.InputStream inputStream, boolean ensureLineFeedAtEndOfFile)
Creates 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
handleEos(boolean previousWasSlashCr)
Handles the end of stream condition.void
mark(int readlimit)
int
read()
private int
readWithUpdate()
Reads the next item from the target, updating internal flags in the process
-
-
-
Constructor Detail
-
UnixLineEndingInputStream
public UnixLineEndingInputStream(java.io.InputStream inputStream, boolean ensureLineFeedAtEndOfFile)
Creates an input stream that filters another stream- Parameters:
inputStream
- The input stream to wrapensureLineFeedAtEndOfFile
- true to ensure that the file ends with LF
-
-
Method Detail
-
close
public void close() throws java.io.IOException
Closes the stream. Also closes the underlying stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
- upon error
-
handleEos
private int handleEos(boolean previousWasSlashCr)
Handles the end of stream condition.- Parameters:
previousWasSlashCr
- Indicates if the last seen was a\r
.- Returns:
- The next char to output to the stream.
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classjava.io.InputStream
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
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
-
-