m.c.m.proxyma.buffers
Class FileBuffer

java.lang.Object
  extended by m.c.m.proxyma.buffers.FileBuffer
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ByteBuffer

public class FileBuffer
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, ByteBuffer

This class implements a ByteBuffer that can be used to store large and small binary data. It uses a temporary file to mantain the data. You can't write simultaneouusly from separate threads (write operations are not thread-safe).

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

Version:
$Id: FileBuffer.java 138 2010-06-20 13:53:32Z marcolinuz $
Author:
Marco Casavecchia Morganti (marcolinuz) [ICQ UIN: 245662445]
See Also:
Serialized Form

Constructor Summary
FileBuffer()
          Create a file buffer over a temporary file.
 
Method Summary
 long appendByte(int data)
          Append the passed byte to the file.
 long appendBytes(byte[] data, int size)
          Append the passed byte array to the buffer storing data into the temporary file.
 java.lang.Object clone()
          This method clones the current object.
protected  void finalize()
          close and delete the temporary file..
 java.lang.String getFileFullPath()
          Obtain the full path of the file with the data
 long getSize()
          Returns the size (in bytes) of the data into the buffer.
 boolean isLocked()
          return false if the buffer is still appendable
 void lock()
          Sets the buffer as ReadOnly an close the output stream on it..
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileBuffer

public FileBuffer()
           throws java.io.IOException
Create a file buffer over a temporary file.

Throws:
java.io.IOException
Method Detail

appendBytes

public long appendBytes(byte[] data,
                        int size)
                 throws java.io.IOException,
                        java.lang.IllegalStateException
Append the passed byte array to the buffer storing data into the temporary file.

Specified by:
appendBytes in interface ByteBuffer
Parameters:
data - a byte array that countains the data to store
size - the number of bytes to copy.
Returns:
the total size of the buffer (total number of introduced bytes).
Throws:
IOException, - IllegalStateException
java.io.IOException
java.lang.IllegalStateException

appendByte

public long appendByte(int data)
                throws java.io.IOException,
                       java.lang.IllegalStateException
Append the passed byte to the file.

Specified by:
appendByte in interface ByteBuffer
Parameters:
data - an integer that rappresents the byte data.
Returns:
the total size of the buffer (total number of introduced bytes).
Throws:
IOException, - IllegalStateException
java.io.IOException
java.lang.IllegalStateException

lock

public void lock()
Sets the buffer as ReadOnly an close the output stream on it.. no more data can be written into this buffer. If so, an IllegalStateException is raised.

Specified by:
lock in interface ByteBuffer

getSize

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

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

getFileFullPath

public java.lang.String getFileFullPath()
Obtain the full path of the file with the data

Returns:
the full path of the file

isLocked

public boolean isLocked()
return false if the buffer is still appendable

Specified by:
isLocked in interface ByteBuffer
Returns:
the current status.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
This method clones the current object.
Because it uses the same file of its parent as storage area, the new clone will be locked.
..in other words the clone can't be modified.

Specified by:
clone in interface ByteBuffer
Overrides:
clone in class java.lang.Object
Returns:
a new and separate instance of the object.
Throws:
java.lang.CloneNotSupportedException - if the clone operation is not supported

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.