Package org.verapdf.as.filters.io
Class ASBufferedInFilter
java.lang.Object
java.io.InputStream
org.verapdf.as.io.ASInputStream
org.verapdf.as.filters.ASInFilter
org.verapdf.as.filters.io.ASBufferedInFilter
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
COSFilterAESDecryptionDefault
,COSFilterASCII85Decode
,COSFilterASCIIHexDecode
,COSFilterFlateDecode
,COSFilterLZWDecode
,COSFilterRC4DecryptionDefault
,COSPredictorDecode
,EexecFilterDecode
Class provides buffered input from input stream.
It has two uses. If the ASBufferedInFilter object is used as a buffered
stream (e. g. in unseekable parsers) then the buffer holds DECODED bytes read
from inlaying stream.
Before using the ASBufferedInFilter in this make sure to call initialize()
method.
In filter classes that are inherited from ASBufferedInFilter the buffer holds
ENCODED bytes that are processed into decoded bytes on read() method calls.
- Author:
- Sergey Shemyakov
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
protected byte[]
static final int
Fields inherited from class org.verapdf.as.io.ASInputStream
isClosed, isSourceClosed, resourceUsers
-
Constructor Summary
ConstructorsConstructorDescriptionASBufferedInFilter
(ASInputStream stream) ASBufferedInFilter
(ASInputStream stream, int buffCapacity) -
Method Summary
Modifier and TypeMethodDescriptionint
addToBuffer
(int bytesToAdd) Reads next portion of data from the underlying stream and appends it to the end of data, contained in internal buffer.byte
Returns the character pointed by buffer begin marker and advances it.int
bufferPopArray
(byte[] buffer, int read) Reads data from internal buffer into passed byte array and advances begin marker.int
void
Closes stream resource.static byte[]
concatenate
(byte[] one, int lengthOne, byte[] two, int lengthTwo) int
feedBuffer
(int bytesToRead) Reads next portion of data from the underlying stream to the internal buffer, updates begin and end pointers and returns number of bytes actually placed in buffer.int
int
int
int
getStream
(int length) Gets a stream that is a piece of this stream.getStreamUntilToken
(byte[] token) Gets a stream that is a piece of this stream.void
This method should be called before using ASBufferedInFilter as buffered stream.boolean
isEOF()
byte
peek()
byte
peek
(int i) int
processBuffer
(int bytesToProcess) Shifts begin marker by up to bytesToProceed bytes to the right of to the end of the buffer if bytesToProceed is too big.int
read
(byte[] buffer) int
read
(byte[] buffer, int size) byte
readByte()
void
reset()
void
int
skip
(int size) Skips given number of decoded bytes in stream.void
unread()
void
unread
(int i) Methods inherited from class org.verapdf.as.filters.ASInFilter
close, decrementResourceUsers, getInputStream, incrementResourceUsers, read, setInputStream
Methods inherited from class org.verapdf.as.io.ASInputStream
createStreamFromStream
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, skip, skipNBytes, transferTo
-
Field Details
-
START_BUFFER_SIZE
public static final int START_BUFFER_SIZE- See Also:
-
BF_BUFFER_SIZE
public static final int BF_BUFFER_SIZE- See Also:
-
buffer
protected byte[] buffer
-
-
Constructor Details
-
ASBufferedInFilter
- Throws:
IOException
-
ASBufferedInFilter
-
-
Method Details
-
initialize
This method should be called before using ASBufferedInFilter as buffered stream.- Throws:
IOException
-
read
Description copied from class:ASInFilter
- Overrides:
read
in classASInFilter
- Throws:
IOException
-
read
Description copied from class:ASInFilter
- Overrides:
read
in classASInFilter
- Throws:
IOException
-
readByte
- Throws:
IOException
-
processBuffer
public int processBuffer(int bytesToProcess) Shifts begin marker by up to bytesToProceed bytes to the right of to the end of the buffer if bytesToProceed is too big.- Parameters:
bytesToProcess
- amount of bytes to shift.- Returns:
- amount of bytes actually processed.
-
feedBuffer
Reads next portion of data from the underlying stream to the internal buffer, updates begin and end pointers and returns number of bytes actually placed in buffer.- Parameters:
bytesToRead
- amount of bytes to read.- Returns:
- amount of bytes actually placed into buffer.
- Throws:
IOException
-
addToBuffer
Reads next portion of data from the underlying stream and appends it to the end of data, contained in internal buffer.- Parameters:
bytesToAdd
- amount of bytes to read.- Returns:
- amount of bytes actually appended to buffer.
- Throws:
IOException
-
getBufferBegin
public int getBufferBegin()- Returns:
- beginning index of unread data in buffer.
-
getBufferEnd
public int getBufferEnd()- Returns:
- index of the end of of valid unread data in buffer.
-
bufferPop
public byte bufferPop()Returns the character pointed by buffer begin marker and advances it.- Returns:
- character, pointed by buffer begin marker.
-
bufferPopArray
Reads data from internal buffer into passed byte array and advances begin marker.- Parameters:
buffer
- is byte array where data will be read.read
- maximal amount of bytes to read.- Returns:
- amount of actually read bytes.
- Throws:
IOException
- if passed buffer is too small to contain necessary amount of bytes.
-
bufferSize
public int bufferSize()- Returns:
- the number of bytes currently available in the buffer.
-
getBufferCapacity
public int getBufferCapacity()- Returns:
- the total capacity of buffer.
-
closeResource
Closes stream resource. There is a difference between closing stream and closing it's resource. Several streams may have the same resource (e. g. the same file stream) and resource should be closed only after all streams using it are closed.- Overrides:
closeResource
in classASInFilter
- Throws:
IOException
-
reset
- Overrides:
reset
in classASInFilter
- Throws:
IOException
-
concatenate
public static byte[] concatenate(byte[] one, int lengthOne, byte[] two, int lengthTwo) -
skip
Skips given number of decoded bytes in stream.- Overrides:
skip
in classASInFilter
- Parameters:
size
- is amount of bytes to skip.- Returns:
- amount of actually skipped bytes.
- Throws:
IOException
- if stream-reading error occurs.
-
peek
- Throws:
IOException
-
peek
- Throws:
IOException
-
unread
- Throws:
IOException
-
unread
- Throws:
IOException
-
isEOF
public boolean isEOF() -
resetReadCounter
public void resetReadCounter() -
getReadCounter
public int getReadCounter() -
getStream
Gets a stream that is a piece of this stream. The next length bytes will be the data in the new stream.- Parameters:
length
- is the length of new stream.- Returns:
- new stream.
- Throws:
IOException
-
getStreamUntilToken
Gets a stream that is a piece of this stream. The data is taken from the current buffer position until the given token is not found.- Parameters:
token
- is the byte array that means the end of stream.- Returns:
- new stream.
- Throws:
IOException
-