Package org.apache.james.mime4j.io
Class BufferedLineReaderInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.james.mime4j.io.LineReaderInputStream
org.apache.james.mime4j.io.BufferedLineReaderInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Input buffer that can be used to search for patterns using Quick Search
algorithm in data read from an
InputStream
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ThreadLocal
<SoftReference<BufferRecycler>> private byte[]
private int
private int
private final int
private byte[]
private int
private int
private int[]
(package private) boolean
private boolean
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionBufferedLineReaderInputStream
(InputStream instream, int buffersize) BufferedLineReaderInputStream
(InputStream instream, int buffersize, int maxLineLen) -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]
buf()
private int
int
byteAt
(int pos) int
capacity()
private void
clear()
void
ensureCapacity
(int len) private void
expand
(int newlen) int
static BufferRecycler
boolean
int
indexOf
(byte b) int
indexOf
(byte[] pattern) Implements quick search algorithm as published byint
indexOf
(byte[] pattern, int off, int len) Implements quick search algorithm as published byint
indexOf
(byte b, int off, int len) protected int
length()
protected int
limit()
boolean
protected int
pos()
int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) protected boolean
int
readLine
(ByteArrayBuffer dst) Reads one line of text into the givenByteArrayBuffer
.void
release()
protected int
skip
(int n) toString()
void
truncate()
boolean
unread
(ByteArrayBuffer buf) Tries to unread the last read line.boolean
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
_recyclerRef
-
truncated
private boolean truncated -
tempBuffer
boolean tempBuffer -
origBuffer
private byte[] origBuffer -
origBufpos
private int origBufpos -
origBuflen
private int origBuflen -
buffer
private byte[] buffer -
bufpos
private int bufpos -
buflen
private int buflen -
shiftTable
private int[] shiftTable -
maxLineLen
private final int maxLineLen
-
-
Constructor Details
-
BufferedLineReaderInputStream
-
BufferedLineReaderInputStream
-
-
Method Details
-
getBufferRecycler
-
expand
private void expand(int newlen) -
ensureCapacity
public void ensureCapacity(int len) -
fillBuffer
- Throws:
IOException
-
bufferLen
private int bufferLen() -
hasBufferedData
public boolean hasBufferedData() -
truncate
public void truncate() -
release
public void release() -
readAllowed
protected boolean readAllowed() -
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classFilterInputStream
-
readLine
Description copied from class:LineReaderInputStream
Reads one line of text into the givenByteArrayBuffer
.- Specified by:
readLine
in classLineReaderInputStream
- Parameters:
dst
- Destination- Returns:
- number of bytes copied or
-1
if the end of the stream has been reached. - Throws:
MaxLineLimitException
- if the line exceeds a limit on the line length imposed by a subclass.IOException
- in case of an I/O error.
-
indexOf
public int indexOf(byte[] pattern, int off, int len) Implements quick search algorithm as published bySUNDAY D.M., 1990, A very fast substring search algorithm, Communications of the ACM . 33(8):132-142.
-
indexOf
public int indexOf(byte[] pattern) Implements quick search algorithm as published bySUNDAY D.M., 1990, A very fast substring search algorithm, Communications of the ACM . 33(8):132-142.
-
indexOf
public int indexOf(byte b, int off, int len) -
indexOf
public int indexOf(byte b) -
byteAt
public int byteAt(int pos) -
buf
protected byte[] buf() -
pos
protected int pos() -
limit
protected int limit() -
length
protected int length() -
capacity
public int capacity() -
skip
protected int skip(int n) -
clear
private void clear() -
toString
-
unread
Description copied from class:LineReaderInputStream
Tries to unread the last read line. Implementation may refuse to unread a new buffer until the previous unread one has been competely consumed. Implementations will directly use the byte array backed by buf, so make sure to not alter it anymore once this method has been called.- Specified by:
unread
in classLineReaderInputStream
- Returns:
- true if the unread has been succesfull.
-
unread
- Specified by:
unread
in classLineReaderInputStream
-