m.c.m.proxyma.buffers
Class RamBuffer

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

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

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

See Also:
Serialized Form

Field Summary
static int LARGE_BINARY_DATA
           
static int SMALL_BINARY_DATA
           
static int TEXT_DATA
           
 
Constructor Summary
RamBuffer(int pageSize)
          This constructor builds a new RamBuffer setting the pagesize to the passed valut and initializes all internal attributes.
 
Method Summary
 long appendByte(int data)
          Append the passed byte to the buffer.
 long appendBytes(byte[] data, int size)
          Append the passed byte array to the buffer making an internal copy of it.
 java.lang.Object clone()
          This method clones the current object.
protected  byte[] getPage(int pageNumber)
          Get the specified page of data
 int getpageSize()
          Obtain the current page size for this buffer
 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.. no more data can be written into it.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEXT_DATA

public static final int TEXT_DATA
See Also:
Constant Field Values

SMALL_BINARY_DATA

public static final int SMALL_BINARY_DATA
See Also:
Constant Field Values

LARGE_BINARY_DATA

public static final int LARGE_BINARY_DATA
See Also:
Constant Field Values
Constructor Detail

RamBuffer

public RamBuffer(int pageSize)
This constructor builds a new RamBuffer setting the pagesize to the passed valut and initializes all internal attributes.

Parameters:
pageSize - the size of single a page (it can have the same size of the data to store).
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 making an internal copy of it.

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 buffer.

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.. no more data can be written into it. 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.

isLocked

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

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

getpageSize

public int getpageSize()
Obtain the current page size for this buffer

Returns:
the page size

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
This method clones the current object.
Because it uses the same buffer 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

getPage

protected byte[] getPage(int pageNumber)
Get the specified page of data

Parameters:
pageNumber - the number of the wanted page
Returns:
the wanted page


Copyright © 2010. All Rights Reserved.