m.c.m.proxyma.buffers
Interface ByteBufferReader

All Known Implementing Classes:
FileBufferReader, RamBufferReader, SmartBufferReader

public interface ByteBufferReader

This is a common interface to read into my Buffer classes. It is a Reader that allows many threads to read data at the same time (thread-safe).

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

Version:
$Id: ByteBufferReader.java 138 2010-06-20 13:53:32Z marcolinuz $
Author:
Marco Casavecchia Morganti (marcolinuz) [marcolinuz-at-gmail.com]

Method Summary
 long getSize()
          Returns the size (in bytes) of the data stored 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 the requested amount of data from the buffer and stores them into the provided byte array.
 void reset()
          Reset the Reader and rewinds it to the begin.
 

Method Detail

readBytes

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

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

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

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

void reset()
           throws java.io.IOException
Reset the Reader and rewinds it to the begin. This is useful to re-read the same buffer without instantiate a new reader on it..

Throws:
java.io.IOException

getWholeBufferAsByteArray

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 data buffers.

Returns:
the buffer content.
Throws:
java.io.IOException

getSize

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

Returns:
the size of the buffer in bytes.


Copyright © 2010. All Rights Reserved.