Class RememberBytesInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.derby.impl.store.raw.data.RememberBytesInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class RememberBytesInputStream extends java.io.FilterInputStreamA 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
Fields Modifier and Type Field Description (package private) ByteHolderbh(package private) booleanrecording(package private) booleanstreamClosed
-
Constructor Summary
Constructors Constructor Description RememberBytesInputStream(java.io.InputStream in, ByteHolder bh)Construct a RememberBytesInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Return 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.ByteHoldergetByteHolder()Get the byteHolder.java.io.InputStreamgetReplayStream()Get an input stream for re-reading the remembered bytes.intnumBytesSaved()Return the number of bytes that have been saved to this byte holder.intputBuf(java.io.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)booleanrecording()Return true iff this RememberBytesInputStream is in recording mode.voidsetInput(java.io.InputStream in)Set the InputStream from which this reads.intshiftToFront()remove the remaining bytes in the byteHolder to the beginning set the position to start recording just after these bytes.longskip(long count)java.lang.StringtoString()
-
-
-
Field Detail
-
bh
ByteHolder bh
-
recording
boolean recording
-
streamClosed
boolean streamClosed
-
-
Constructor Detail
-
RememberBytesInputStream
public RememberBytesInputStream(java.io.InputStream in, ByteHolder bh)Construct a RememberBytesInputStream.- Parameters:
bh- for storing the remembered bytes. (must be in writing mode.
-
-
Method Detail
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException- thrown on an io error spooling rememberd bytes to backing storage.- See Also:
InputStream.read()
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException- thrown on an io error spooling rememberd bytes to backing storage.- See Also:
InputStream.read()
-
fillBuf
public long fillBuf(int len) throws java.io.IOExceptionread 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:
java.io.IOException- thrown on an io error spooling rememberd bytes to backing storage.
-
putBuf
public int putBuf(java.io.OutputStream out, int len) throws java.io.IOExceptionread len bytes from the byte holder, and write it to the output stream.- Throws:
java.io.IOException- thrown on an io error spooling rememberd bytes to backing storage.
-
skip
public long skip(long count) throws java.io.IOException- Overrides:
skipin classjava.io.FilterInputStream- Throws:
java.io.IOException- thrown on an io error spooling rememberd bytes to backing storage.- See Also:
InputStream.skip(long)
-
getReplayStream
public java.io.InputStream getReplayStream() throws java.io.IOExceptionGet an input stream for re-reading the remembered bytes.- Throws:
java.io.IOException
-
getByteHolder
public ByteHolder getByteHolder() throws java.io.IOException
Get the byteHolder.- Throws:
java.io.IOException
-
clear
public void clear() throws java.io.IOExceptionClear all the remembered bytes. This stream will remember any bytes read after this call.- Throws:
java.io.IOException- thrown on an io error clearing backing storage.
-
setInput
public void setInput(java.io.InputStream in)
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
public int available() throws java.io.IOExceptionReturn the number of bytes remains in the byteHolder for reading, without setting the write/read mode.- Overrides:
availablein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
numBytesSaved
public int numBytesSaved() throws java.io.IOExceptionReturn 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:
java.io.IOException
-
shiftToFront
public int shiftToFront() throws java.io.IOExceptionremove 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:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
-