Top Description Fields Constructors Methods
org.apache.derby.impl.store.raw.data

public Class RememberBytesInputStream

extends FilterInputStream
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager, java.io.FilterInputStream, .IOException, .InputStream, .OutputStream

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

Modifier and TypeField and Description
pack-priv ByteHolder
pack-priv boolean
pack-priv boolean
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
RememberBytesInputStream(InputStream in, ByteHolder
for storing the remembered bytes. (must be in writing mode.
bh
)

Construct a RememberBytesInputStream.

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides java.io.FilterInputStream.available.

Return the number of bytes remains in the byteHolder for reading, without setting the write/read mode.

public void
clear()

Clear all the remembered bytes.

public long
fillBuf(int len)

read len bytes from the input stream, and store it in the byte holder.

public ByteHolder
getByteHolder()

Get the byteHolder.

public InputStream
getReplayStream()

Get an input stream for re-reading the remembered bytes.

public int
numBytesSaved()

Return the number of bytes that have been saved to this byte holder.

public int
putBuf(OutputStream out, int len)

read len bytes from the byte holder, and write it to the output stream.

public int
read()

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.

public boolean
recording()

Return true iff this RememberBytesInputStream is in recording mode.

public void
setInput(InputStream in)

Set the InputStream from which this reads.

public int
shiftToFront()

remove the remaining bytes in the byteHolder to the beginning set the position to start recording just after these bytes.

public long
skip(long
the number of bytes to be skipped.
count
)

Overrides java.io.FilterInputStream.skip.

Skips over and discards n bytes of data from the input stream.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.io.FilterInputStream:
closemarkmarkSupportedreadreset

Field Detail

bhback to summary
pack-priv ByteHolder bh
recordingback to summary
pack-priv boolean recording
streamClosedback to summary
pack-priv boolean streamClosed

Constructor Detail

RememberBytesInputStreamback to summary
public RememberBytesInputStream(InputStream in, ByteHolder bh)

Construct a RememberBytesInputStream.

Parameters
bh:ByteHolder

for storing the remembered bytes. (must be in writing mode.

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.FilterInputStream.available.

Return the number of bytes remains in the byteHolder for reading, without setting the write/read mode.

Returns:int

Doc from java.io.FilterInputStream.available.

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.

Exceptions
IOException:

Doc from java.io.FilterInputStream.available.

if an I/O error occurs.

clearback to summary
public void clear() throws IOException

Clear all the remembered bytes. This stream will remember any bytes read after this call.

Exceptions
IOException:
thrown on an io error clearing backing storage.
fillBufback to summary
public long fillBuf(int len) throws IOException

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

Exceptions
IOException:
thrown on an io error spooling rememberd bytes to backing storage.
getByteHolderback to summary
public ByteHolder getByteHolder() throws IOException

Get the byteHolder.

getReplayStreamback to summary
public InputStream getReplayStream() throws IOException

Get an input stream for re-reading the remembered bytes.

numBytesSavedback to summary
public int numBytesSaved() throws IOException

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.

putBufback to summary
public int putBuf(OutputStream out, int len) throws IOException

read len bytes from the byte holder, and write it to the output stream.

Exceptions
IOException:
thrown on an io error spooling rememberd bytes to backing storage.
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Exceptions
IOException:
thrown on an io error spooling rememberd bytes to backing storage.
See Also
java.io.InputStream#read
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Exceptions
IOException:
thrown on an io error spooling rememberd bytes to backing storage.
See Also
java.io.InputStream#read
recordingback to summary
public boolean recording()

Return true iff this RememberBytesInputStream is in recording mode.

setInputback to summary
public void setInput(InputStream in)

Set the InputStream from which this reads.

Please note this does not clear remembered bytes.

shiftToFrontback to summary
public int shiftToFront() throws IOException

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.

skipback to summary
public long skip(long count) throws IOException

Overrides java.io.FilterInputStream.skip.

Doc from java.io.FilterInputStream.skip.

Skips over and discards n bytes of data from the input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

Parameters
count:long

the number of bytes to be skipped.

Returns:long

the actual number of bytes skipped.

Exceptions
IOException:
thrown on an io error spooling rememberd bytes to backing storage.
See Also
java.io.InputStream#skip
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

See Also
java.lang.Object#toString