Class RememberBytesInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.derby.impl.store.raw.data.RememberBytesInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
A FilterInputStream that remembers read or skipped bytes.
In record mode this stream remembers all the bytes a caller reads or skips. After reading some bytes this returns a 'replay' stream to re-read them.
A caller may call getReplaySteam to get a stream to re-read the the remembered bytes. Any number of calls to getReplayStream are supported.
The clear function causes this stream to forget the remembered bytes and re-enter record mode.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) ByteHolder(package private) boolean(package private) booleanFields inherited from class FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a RememberBytesInputStream. -
Method Summary
Modifier and TypeMethodDescriptionintReturn the number of bytes remains in the byteHolder for reading, without setting the write/read mode.voidclear()Clear all the remembered bytes.longfillBuf(int len) read len bytes from the input stream, and store it in the byte holder.Get the byteHolder.Get an input stream for re-reading the remembered bytes.intReturn the number of bytes that have been saved to this byte holder.intputBuf(OutputStream out, int len) read len bytes from the byte holder, and write it to the output stream.intread()intread(byte[] b, int off, int len) booleanReturn true iff this RememberBytesInputStream is in recording mode.voidsetInput(InputStream in) Set the InputStream from which this reads.intremove the remaining bytes in the byteHolder to the beginning set the position to start recording just after these bytes. returns how many bytes was transfered to the beginning.longskip(long count) toString()Methods inherited from class FilterInputStream
close, mark, markSupported, read, resetMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
bh
ByteHolder bh -
recording
boolean recording -
streamClosed
boolean streamClosed
-
-
Constructor Details
-
RememberBytesInputStream
Construct a RememberBytesInputStream.- Parameters:
bh- for storing the remembered bytes. (must be in writing mode.
-
-
Method Details
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException- thrown on an io error spooling rememberd bytes to backing storage.- See Also:
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException- thrown on an io error spooling rememberd bytes to backing storage.- See Also:
-
fillBuf
read len bytes from the input stream, and store it in the byte holder. Note, fillBuf does not return negative values, if there are no bytes to store in the byteholder, it will return 0- Throws:
IOException- thrown on an io error spooling rememberd bytes to backing storage.
-
putBuf
read len bytes from the byte holder, and write it to the output stream.- Throws:
IOException- thrown on an io error spooling rememberd bytes to backing storage.
-
skip
- Overrides:
skipin classFilterInputStream- Throws:
IOException- thrown on an io error spooling rememberd bytes to backing storage.- See Also:
-
getReplayStream
Get an input stream for re-reading the remembered bytes.- Throws:
IOException
-
getByteHolder
-
clear
Clear all the remembered bytes. This stream will remember any bytes read after this call.- Throws:
IOException- thrown on an io error clearing backing storage.
-
setInput
Set the InputStream from which this reads.Please note this does not clear remembered bytes.
-
recording
public boolean recording()Return true iff this RememberBytesInputStream is in recording mode. -
available
Return the number of bytes remains in the byteHolder for reading, without setting the write/read mode.- Overrides:
availablein classFilterInputStream- Throws:
IOException
-
numBytesSaved
Return the number of bytes that have been saved to this byte holder. This result is different from available() as it is unaffected by the current read position on the ByteHolder.- Throws:
IOException
-
shiftToFront
remove the remaining bytes in the byteHolder to the beginning set the position to start recording just after these bytes. returns how many bytes was transfered to the beginning.- Throws:
IOException
-
toString
-