m.c.m.proxyma.buffers
Class FileBufferReader

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

public class FileBufferReader
extends java.lang.Object
implements ByteBufferReader

This class implements a Reader Class for the FileBuffer. 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: FileBufferReader.java 138 2010-06-20 13:53:32Z marcolinuz $
Author:
Marco Casavecchia Morganti (marcolinuz) [ICQ UIN: 245662445]

Constructor Summary
FileBufferReader(FileBuffer fileBuffer)
          Create a reader ovedr the given FileBuffer
 
Method Summary
protected  void finalize()
          close and delete the temporary file..
 long getSize()
          Returns the size (in bytes) of the data into the buffer.
 byte[] getWholeBufferAsByteArray()
          returns the whole file into a new byte array.
 int readByte()
          Read a single byte of data from the buffer
 int readBytes(byte[] data, int size)
          Reads data from the file 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, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileBufferReader

public FileBufferReader(FileBuffer fileBuffer)
                 throws java.io.IOException
Create a reader ovedr the given FileBuffer

Throws:
java.io.IOException
Method Detail

readBytes

public int readBytes(byte[] data,
                     int size)
              throws java.io.IOException
Reads data from the file 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

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 file into a new byte array. WARNING! This method could be memory hungry if used with large size files.

Specified by:
getWholeBufferAsByteArray in interface ByteBufferReader
Returns:
the generated byteArray;
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.

finalize

protected void finalize()
                 throws java.lang.Throwable
close and delete the temporary file..

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


Copyright © 2010. All Rights Reserved.