m.c.m.proxyma.buffers
Class SmartBufferReader

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

public class SmartBufferReader
extends java.lang.Object
implements ByteBufferReader

This class implements a Reader Class for the SmartBuffer. To read more than once the same data you have to execute reset() method between every read operation.

NOTE: this software is released under GPL License. See the LICENSE of this distribution for more informations.

Version:
$Id: SmartBufferReader.java 138 2010-06-20 13:53:32Z marcolinuz $

Author:
Marco Casavecchia Morganti (marcolinuz) [ICQ UIN: 245662445]

Constructor Summary
SmartBufferReader(SmartBuffer buffer)
          This constructor builds a new Reader based upon the passed SmartBuffer.
 
Method Summary
 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

SmartBufferReader

public SmartBufferReader(SmartBuffer buffer)
                  throws java.io.IOException
This constructor builds a new Reader based upon the passed SmartBuffer.

Parameters:
buffer - the SmartBuffer where read data
Throws:
java.io.IOException
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 - if something goes wrong

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 - if something goes wrong

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.


Copyright © 2010. All Rights Reserved.