m.c.m.proxyma.buffers
Class RamBufferReader

java.lang.Object
  extended by m.c.m.proxyma.buffers.RamBufferReader
All Implemented Interfaces:
ByteBufferReader

public class RamBufferReader
extends java.lang.Object
implements ByteBufferReader

This class is a custom buffer to read and write byte data into RAM


Constructor Summary
RamBufferReader(RamBuffer buffer)
          This constructor builds a new Reader based upon the passed RamBuffer.
 
Method Summary
 long getBytesLeftCount()
          Obtain the number of unreaded bytes into the buffer
 long getSize()
          Returns the size (in bytes) of the data into the buffer.
 byte[] getWholeBufferAsByteArray()
          Returns the whole buffer into a byte array.
 int readByte()
          Read a single byte of data from the buffer
 int readBytes(byte[] data, int size)
          Reads data from the buffer and stores them into the provided byte array.
 void reset()
          Resets the Reader, next read operation will start fom the begin of the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RamBufferReader

public RamBufferReader(RamBuffer buffer)
This constructor builds a new Reader based upon the passed RamBuffer.

Parameters:
buffer - the constant value that specifies the type of data to store.
Method Detail

readBytes

public int readBytes(byte[] data,
                     int size)
              throws java.io.IOException
Reads data from the buffer and stores them into the provided byte array.

Specified by:
readBytes in interface ByteBufferReader
Parameters:
data - the byte array where data will be written
size - the max number of data that can be written.
Returns:
the number of transfered bytes or -1 if there are no more data to read (the end of the buffer was reached).
Throws:
java.io.IOException

readByte

public int readByte()
             throws java.io.IOException
Read a single byte of data from the buffer

Specified by:
readByte in interface ByteBufferReader
Returns:
the int value of the byte or -1 if the end of the data was reached.
Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException
Resets the Reader, next read operation will start fom the begin of the buffer.

Specified by:
reset in interface ByteBufferReader
Throws:
java.io.IOException

getWholeBufferAsByteArray

public byte[] getWholeBufferAsByteArray()
                                 throws java.io.IOException
Returns the whole buffer into a byte array. WARNING! This method could be memory hungry if used with large size buffers.

Specified by:
getWholeBufferAsByteArray in interface ByteBufferReader
Returns:
the buffer content.
Throws:
java.io.IOException

getSize

public long getSize()
Returns the size (in bytes) of the data into the buffer.

Specified by:
getSize in interface ByteBufferReader
Returns:
the size of the buffer in bytes.

getBytesLeftCount

public long getBytesLeftCount()
Obtain the number of unreaded bytes into the buffer

Returns:
number of unreaded bytes.


Copyright © 2010. All Rights Reserved.