com.ucware.coff
Interface RandomAccessData


public interface RandomAccessData

A RandomAccessData provides the interface to support the seek and getPointer methods on the input data.


Method Summary
 long getPointer()
          Returns the current offset in this RandomAccessData.
 int read()
          Reads the next byte of data.
 int read(byte[] b)
          Reads some number of bytes from the data and stores them into the buffer array b.
 void seek(long pos)
          Sets the offset, measured from the beginning of this data, at which the next read or write occurs.
 long size()
          Returns the size of this data.
 

Method Detail

getPointer

long getPointer()
                throws java.io.IOException
Returns the current offset in this RandomAccessData.

Returns:
the offset from the beginning of the data, in bytes, at which the next read or write occurs. 0 is the first value.
Throws:
java.io.IOException

seek

void seek(long pos)
          throws java.io.IOException
Sets the offset, measured from the beginning of this data, at which the next read or write occurs. The offset may be set beyond the size. Setting the offset beyond the size of the data does not change the data size.

Parameters:
pos - the offset position, measured in bytes from the beginning of the data, at which to set the data pointer.
Throws:
java.io.IOException

size

long size()
          throws java.io.IOException
Returns the size of this data.

Returns:
the size of this data, measured in bytes.
Throws:
java.io.IOException

read

int read()
         throws java.io.IOException
Reads the next byte of data. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the data 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.

A subclass must provide an implementation of this method.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - if an I/O error occurs.

read

int read(byte[] b)
         throws java.io.IOException
Reads some number of bytes from the data and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

If b is null, a NullPointerException is thrown. If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[0], the next one into b[1], and so on. The number of bytes read is, at most, equal to the length of b. Let k be the number of bytes actually read; these bytes will be stored in elements b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected.

If the first byte cannot be read for any reason other than end of data, then an IOException is thrown.

Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 is there is no more data.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
InputStream.read(byte[], int, int)