org.apache.derby.impl.store.raw.data
Interface ByteHolder

All Known Implementing Classes:
MemByteHolder

public interface ByteHolder

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
 int available()
          Return the number of bytes that can be read from this ByteHolder without blocking on an IO.
 void clear()
          Clear the bytes from the ByteHolder and place it in writing mode.
 ByteHolder cloneEmpty()
          Return a byte holder matching existing type and size of current ByteHolder, but don't bother to fill the bytes.
 int numBytesSaved()
          Return the number of bytes that have been saved to this byte holder.
 int read()
          Read a byte from this ByteHolder.
 int read(byte[] b, int off, int len)
          Read up to 'len' bytes from this ByteHolder and store them in an array at offset 'off'.
 int read(java.io.OutputStream out, int len)
          Read from the ByteHolder.
 int shiftToFront()
          shift the remaining unread bytes to the beginning of the byte holder
 long skip(long count)
          Skip over the specified number of bytes in a ByteHolder.
 void startReading()
          Place a ByteHolder in reading mode.
 void write(byte[] data, int offset, int len)
          Write len bytes of data starting at 'offset' to this ByteHolder.
 long write(java.io.InputStream in, long count)
          Write up to count bytes from an input stream to this ByteHolder.
 void write(int b)
          Write a byte to this ByteHolder.
 boolean writingMode()
          Return true if this is in writing mode.
 

Method Detail

write

void write(int b)
           throws java.io.IOException
Write a byte to this ByteHolder.

The ByteHolder must be in writing mode to call this.

Throws:
java.io.IOException

write

void write(byte[] data,
           int offset,
           int len)
           throws java.io.IOException
Write len bytes of data starting at 'offset' to this ByteHolder.

The ByteHolder must be in writing mode to call this.

Throws:
java.io.IOException

write

long write(java.io.InputStream in,
           long count)
           throws java.io.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:
the number of bytes written.
Throws:
java.io.IOException - thrown when reading in causes an error.

clear

void clear()
           throws java.io.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.

Throws:
java.io.IOException

startReading

void startReading()
                  throws java.io.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.

Throws:
java.io.IOException

read

int read()
         throws java.io.IOException
Read a byte from this ByteHolder.

The ByteHolder must be in reading mode to call this.

Returns:
The byte or -1 if there are no bytes available.
Throws:
java.io.IOException

read

int read(byte[] b,
         int off,
         int len)
         throws java.io.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:
the number of bytes read or -1 if the this ByteHolder has no more bytes.
Throws:
java.io.IOException

read

int read(java.io.OutputStream out,
         int len)
         throws java.io.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:
the number of bytes read or -1 if the this ByteHolder has no more bytes.
Throws:
java.io.IOException

shiftToFront

int shiftToFront()
                 throws java.io.IOException
shift the remaining unread bytes to the beginning of the byte holder

Throws:
java.io.IOException

available

int available()
              throws java.io.IOException
Return the number of bytes that can be read from this ByteHolder without blocking on an IO.

Throws:
java.io.IOException

numBytesSaved

int numBytesSaved()
                  throws java.io.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.

Throws:
java.io.IOException

skip

long skip(long count)
          throws java.io.IOException
Skip over the specified number of bytes in a ByteHolder.

Throws:
java.io.IOException

writingMode

boolean writingMode()
Return true if this is in writing mode.


cloneEmpty

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:
An empty ByteHolder.

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.