com.sun.labs.minion.util.buffer
Interface ReadableBuffer

All Superinterfaces:
Buffer
All Known Implementing Classes:
ArrayBuffer, ChannelReadableBuffer, FileBackedPostingsInput, FileReadableBuffer, NIOBuffer, StdBufferImpl, StdReadableImpl

public interface ReadableBuffer
extends Buffer

An interface for buffers that can be read from. The main operations on such buffers are the get() operations and the various byteDecode() operations.

Unlike WriteableBuffers, we don't provide any methods for reading in a readable buffer. This is the responsibility of the PostingsInput implementations.

See Also:
WriteableBuffer, PostingsInput

Method Summary
 int byteDecode()
          Decodes an integer stored using our 7 bit encoding scheme.
 int byteDecode(int nBytes)
          Decodes a postive integer that was coded using a specific number of bytes.
 int byteDecode(int pos, int nBytes)
          Decodes a postive integer that was coded using a specific number of bytes from a specific position in the buffer.
 long byteDecodeLong()
          Decodes a long stored using the 7 bit encoding.
 long byteDecodeLong(int nBytes)
          Decodes a postive long that was coded using a specific number of bytes.
 long byteDecodeLong(int pos, int nBytes)
          Decodes a postive long that was coded using a specific number of bytes from a given position.
 int countBits()
          Counts the number of bits that are on in the buffer.
 float decodeFloat()
          Decode a float stored in 4 bytes.
 ReadableBuffer duplicate()
          Duplicates this buffer, so that it can be used safely by other readers.
 byte get()
          Gets a byte from this buffer.
 byte get(int i)
          Gets a byte from this buffer at the given position.
 java.lang.String getString()
          Decodes a string from this buffer.
 int skipByteEncoded()
          Skips an integer encoded using the 7 bit encoding without actually decoding the value.
 ReadableBuffer slice(int p, int s)
          Slices this buffer so that a sub-buffer can be used.
 boolean test(int bitIndex)
          Tests whether a given bit is true or false.
 
Methods inherited from interface com.sun.labs.minion.util.buffer.Buffer
limit, limit, position, position, remaining
 

Method Detail

duplicate

ReadableBuffer duplicate()
Duplicates this buffer, so that it can be used safely by other readers.

Returns:
A new buffer that is a duplicate of the current buffer. The new buffer will share the underlying representation of the buffer, but will have an independant position.

slice

ReadableBuffer slice(int p,
                     int s)
Slices this buffer so that a sub-buffer can be used. The buffer is sliced from the current position.

Parameters:
p - The position at which the buffer should be sliced.
s - The number of bytes that should be in the sliced buffer.
Returns:
A new buffer that contains a slice of the data from this buffer. The new buffer will share the underlying representation of the data, but data will be read starting from the given offset and the new buffer will be limited to the given size.

get

byte get()
Gets a byte from this buffer.

Returns:
The byte at the current position. Calling this method advances the position.

get

byte get(int i)
Gets a byte from this buffer at the given position.

Parameters:
i - The position from which we would like to read a byte.
Returns:
The byte at the given position.

byteDecode

int byteDecode(int nBytes)
Decodes a postive integer that was coded using a specific number of bytes.

Parameters:
nBytes - The number of bytes to use.
Returns:
the decoded number.

byteDecode

int byteDecode(int pos,
               int nBytes)
Decodes a postive integer that was coded using a specific number of bytes from a specific position in the buffer.

Parameters:
pos - The position to decode from.
nBytes - The number of bytes to use.
Returns:
the decoded number.

byteDecodeLong

long byteDecodeLong(int nBytes)
Decodes a postive long that was coded using a specific number of bytes.

Parameters:
nBytes - The number of bytes to use.
Returns:
the decoded number.

byteDecodeLong

long byteDecodeLong(int pos,
                    int nBytes)
Decodes a postive long that was coded using a specific number of bytes from a given position.

Parameters:
pos - The position to decode from.
nBytes - The number of bytes to use.
Returns:
the decoded number.

byteDecode

int byteDecode()
Decodes an integer stored using our 7 bit encoding scheme.

Returns:
the decoded integer.
See Also:
WriteableBuffer.byteEncode(long, int)

byteDecodeLong

long byteDecodeLong()
Decodes a long stored using the 7 bit encoding.

Returns:
the decoded long.
See Also:
WriteableBuffer.byteEncode(long, int)

decodeFloat

float decodeFloat()
Decode a float stored in 4 bytes.

Returns:
the decoded float.

skipByteEncoded

int skipByteEncoded()
Skips an integer encoded using the 7 bit encoding without actually decoding the value.

Returns:
the number of bytes skipped.
See Also:
WriteableBuffer.byteEncode(long, int)

getString

java.lang.String getString()
Decodes a string from this buffer.

Returns:
The string.
See Also:
WriteableBuffer.encode(CharSequence)

test

boolean test(int bitIndex)
Tests whether a given bit is true or false.

Parameters:
bitIndex - the index of the bit to test.
Returns:
true if the bit is 1, false if it is 0

countBits

int countBits()
Counts the number of bits that are on in the buffer.

Returns:
The number of 1 bits in the buffer.