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

public Interface ByteHolder

Known Direct Implementers
org.apache.derby.impl.store.raw.data.MemByteHolder
Imports
java.io.IOException, .InputStream, .OutputStream

Holder for a growing sequence of bytes. The ByteHolder supports a writing phase in which a caller appends bytes to the ByteHolder. Later the caller may read the bytes out of the ByteHolder in the order they were written.

Method Summary

Modifier and TypeMethod and Description
public int
available()

Return the number of bytes that can be read from this ByteHolder without blocking on an IO.

public void
clear()

Clear the bytes from the ByteHolder and place it in writing mode.

public ByteHolder

Returns:

An empty ByteHolder.
cloneEmpty
()

Return a byte holder matching existing type and size of current ByteHolder, but don't bother to fill the bytes.

public int
numBytesSaved()

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

public int

Returns:

The byte or -1 if there are no bytes available.
read
()

Read a byte from this ByteHolder.

public int

Returns:

the number of bytes read or -1 if the this ByteHolder has no more bytes.
read
(byte[] b, int off, int len)

Read up to 'len' bytes from this ByteHolder and store them in an array at offset 'off'.

public int

Returns:

the number of bytes read or -1 if the this ByteHolder has no more bytes.
read
(OutputStream out, int len)

Read from the ByteHolder.

public int
shiftToFront()

shift the remaining unread bytes to the beginning of the byte holder

public long
skip(long count)

Skip over the specified number of bytes in a ByteHolder.

public void
startReading()

Place a ByteHolder in reading mode.

public void
write(int b)

Write a byte to this ByteHolder.

public void
write(byte[] data, int offset, int len)

Write len bytes of data starting at 'offset' to this ByteHolder.

public long

Returns:

the number of bytes written.
write
(InputStream in, long count)

Write up to count bytes from an input stream to this ByteHolder.

public boolean
writingMode()

Return true if this is in writing mode.

Method Detail

availableback to summary
public int available() throws IOException

Return the number of bytes that can be read from this ByteHolder without blocking on an IO.

clearback to summary
public void clear() throws IOException

Clear the bytes from the ByteHolder and place it in writing mode. This may not free the memory the ByteHolder uses to store data.

cloneEmptyback to summary
public ByteHolder cloneEmpty()

Return a byte holder matching existing type and size of current ByteHolder, but don't bother to fill the bytes. Normal usage is expected to reset the holding stream to the beginning, so the copy of current state would be wasted.

Returns:ByteHolder

An empty ByteHolder.

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.

readback to summary
public int read() throws IOException

Read a byte from this ByteHolder.

The ByteHolder must be in reading mode to call this.

Returns:int

The byte or -1 if there are no bytes available.

readback to summary
public int read(byte[] b, int off, int len) throws IOException

Read up to 'len' bytes from this ByteHolder and store them in an array at offset 'off'.

The ByteHolder must be in reading mode to call this.

Returns:int

the number of bytes read or -1 if the this ByteHolder has no more bytes.

readback to summary
public int read(OutputStream out, int len) throws IOException

Read from the ByteHolder.

Read up to 'len' bytes from this ByteHolder and write them to the OutputStream

The ByteHolder must be in reading mode to call this.

Returns:int

the number of bytes read or -1 if the this ByteHolder has no more bytes.

shiftToFrontback to summary
public int shiftToFront() throws IOException

shift the remaining unread bytes to the beginning of the byte holder

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

Skip over the specified number of bytes in a ByteHolder.

startReadingback to summary
public void startReading() throws IOException

Place a ByteHolder in reading mode. After this call, reads scan bytes sequentially in the order they were written to the ByteHolder starting from the first byte. When the ByteHolder is already in readmode this simply arranges for reads to start at the beginning of the sequence of saved bytes.

writeback to summary
public void write(int b) throws IOException

Write a byte to this ByteHolder.

The ByteHolder must be in writing mode to call this.

writeback to summary
public void write(byte[] data, int offset, int len) throws IOException

Write len bytes of data starting at 'offset' to this ByteHolder.

The ByteHolder must be in writing mode to call this.

writeback to summary
public long write(InputStream in, long count) throws IOException

Write up to count bytes from an input stream to this ByteHolder. This may write fewer bytes if it encounters an end of file on the input stream.

Returns:long

the number of bytes written.

Exceptions
IOException:
thrown when reading in causes an error.
writingModeback to summary
public boolean writingMode()

Return true if this is in writing mode.