com.sun.labs.minion.util.buffer
Class StdReadableImpl

java.lang.Object
  extended by com.sun.labs.minion.util.buffer.StdReadableImpl
All Implemented Interfaces:
Buffer, ReadableBuffer
Direct Known Subclasses:
ChannelReadableBuffer, FileReadableBuffer

public abstract class StdReadableImpl
extends java.lang.Object
implements ReadableBuffer

A class that implements the decoding routines in ReadableBuffer so that readable only buffer implementations can share it.


Constructor Summary
StdReadableImpl()
           
 
Method Summary
 int byteDecode()
          Decodes an integer stored using the minimal number of bytes.
 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 byte 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 set in a buffer.
 float decodeFloat()
          Decode a float stored in 4 bytes.
 java.lang.String getString()
          Gets a string from this buffer.
 int skipByteEncoded()
          Skips a byte encoded integer without decoding it.
 boolean test(int bitIndex)
          Tests whether a given bit is true or false.
 java.lang.String toString()
          Gets a string representation of the bytes in this buffer.
 java.lang.String toString(int mode)
          Print the bits in the buffer in the order in which they actually occur.
 java.lang.String toString(int start, int end)
          Print the bits in the buffer in the order in which they actually occur.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.sun.labs.minion.util.buffer.ReadableBuffer
duplicate, get, get, slice
 
Methods inherited from interface com.sun.labs.minion.util.buffer.Buffer
limit, limit, position, position, remaining
 

Constructor Detail

StdReadableImpl

public StdReadableImpl()
Method Detail

byteDecode

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

Specified by:
byteDecode in interface ReadableBuffer
Parameters:
nBytes - The number of bytes to use.
Returns:
the decoded number.

byteDecode

public 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.

Specified by:
byteDecode in interface ReadableBuffer
Parameters:
pos - The position to decode from.
nBytes - The number of bytes to use.
Returns:
the decoded number.

byteDecodeLong

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

Specified by:
byteDecodeLong in interface ReadableBuffer
Parameters:
nBytes - The number of bytes to use.
Returns:
the decoded number.

byteDecodeLong

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

Specified by:
byteDecodeLong in interface ReadableBuffer
Parameters:
pos - The position to decode from.
nBytes - The number of bytes to use.
Returns:
the decoded number.

byteDecode

public int byteDecode()
Decodes an integer stored using the minimal number of bytes.

Specified by:
byteDecode in interface ReadableBuffer
Returns:
the decoded integer.
See Also:
WriteableBuffer.byteEncode(long, int)

byteDecodeLong

public long byteDecodeLong()
Decodes a long stored using the byte encoding.

Specified by:
byteDecodeLong in interface ReadableBuffer
Returns:
the decoded long.
See Also:
WriteableBuffer.byteEncode(long, int)

skipByteEncoded

public int skipByteEncoded()
Skips a byte encoded integer without decoding it.

Specified by:
skipByteEncoded in interface ReadableBuffer
Returns:
the number of bytes skipped.
See Also:
WriteableBuffer.byteEncode(long, int)

decodeFloat

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

Specified by:
decodeFloat in interface ReadableBuffer
Returns:
the decoded float.

test

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

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

countBits

public int countBits()
Counts the number of bits that are set in a buffer.

Specified by:
countBits in interface ReadableBuffer
Returns:
The number of 1 bits in the buffer.

getString

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

Specified by:
getString in interface ReadableBuffer
Returns:
A string representation of this buffer.
See Also:
WriteableBuffer.encode(CharSequence)

toString

public java.lang.String toString()
Gets a string representation of the bytes in this buffer.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the buffer.

toString

public java.lang.String toString(int mode)
Print the bits in the buffer in the order in which they actually occur.

Parameters:
mode - The type of print out required.
Returns:
A string representation of the buffer.

toString

public java.lang.String toString(int start,
                                 int end)
Print the bits in the buffer in the order in which they actually occur.

Parameters:
start - The starting position in the buffer from which to display the bytes.
end - The (exclusive) ending position in the buffer.
Returns:
A string representation of the buffer.