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:
java.io.Closeable,java.lang.AutoCloseable
public class BufferedLineReaderInputStream extends LineReaderInputStream
Input buffer that can be used to search for patterns using Quick Search algorithm in data read from anInputStream.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>>_recyclerRefprivate byte[]bufferprivate intbuflenprivate intbufposprivate intmaxLineLenprivate byte[]origBufferprivate intorigBuflenprivate intorigBufposprivate int[]shiftTable(package private) booleantempBufferprivate booleantruncated
-
Constructor Summary
Constructors Constructor Description BufferedLineReaderInputStream(java.io.InputStream instream, int buffersize)BufferedLineReaderInputStream(java.io.InputStream instream, int buffersize, int maxLineLen)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]buf()private intbufferLen()intbyteAt(int pos)intcapacity()private voidclear()voidensureCapacity(int len)private voidexpand(int newlen)intfillBuffer()static BufferRecyclergetBufferRecycler()booleanhasBufferedData()intindexOf(byte b)intindexOf(byte[] pattern)Implements quick search algorithm as published byintindexOf(byte[] pattern, int off, int len)Implements quick search algorithm as published byintindexOf(byte b, int off, int len)protected intlength()protected intlimit()booleanmarkSupported()protected intpos()intread()intread(byte[] b)intread(byte[] b, int off, int len)protected booleanreadAllowed()intreadLine(ByteArrayBuffer dst)Reads one line of text into the givenByteArrayBuffer.voidrelease()protected intskip(int n)java.lang.StringtoString()voidtruncate()booleanunread(ByteArrayBuffer buf)Tries to unread the last read line.booleanunread(RecycledByteArrayBuffer buf)
-
-
-
Field Detail
-
_recyclerRef
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>> _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
-
-
Method Detail
-
getBufferRecycler
public static BufferRecycler getBufferRecycler()
-
expand
private void expand(int newlen)
-
ensureCapacity
public void ensureCapacity(int len)
-
fillBuffer
public int fillBuffer() throws java.io.IOException- Throws:
java.io.IOException
-
bufferLen
private int bufferLen()
-
hasBufferedData
public boolean hasBufferedData()
-
truncate
public void truncate()
-
release
public void release()
-
readAllowed
protected boolean readAllowed()
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classjava.io.FilterInputStream
-
readLine
public int readLine(ByteArrayBuffer dst) throws MaxLineLimitException, java.io.IOException
Description copied from class:LineReaderInputStreamReads one line of text into the givenByteArrayBuffer.- Specified by:
readLinein classLineReaderInputStream- Parameters:
dst- Destination- Returns:
- number of bytes copied or
-1if the end of the stream has been reached. - Throws:
MaxLineLimitException- if the line exceeds a limit on the line length imposed by a subclass.java.io.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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
unread
public boolean unread(ByteArrayBuffer buf)
Description copied from class:LineReaderInputStreamTries 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:
unreadin classLineReaderInputStream- Returns:
- true if the unread has been succesfull.
-
unread
public boolean unread(RecycledByteArrayBuffer buf)
- Specified by:
unreadin classLineReaderInputStream
-
-