Package com.mckoi.store
Class HeapStore.HeapArea
- java.lang.Object
-
- com.mckoi.store.HeapStore.HeapArea
-
- All Implemented Interfaces:
Area
,MutableArea
- Direct Known Subclasses:
HeapStore.HeapAreaWriter
- Enclosing class:
- HeapStore
private static class HeapStore.HeapArea extends java.lang.Object implements MutableArea
An implementation of Area for a byte[] array from the heap.
-
-
Field Summary
Fields Modifier and Type Field Description private int
end_pointer
The end pointer of the area.private byte[]
heap_area
A pointer to the byte[] array representing the entire area.private long
id
The ID of this area.private int
position
The current pointer into the area.private int
start_pointer
The start pointer in the heap area.
-
Constructor Summary
Constructors Constructor Description HeapArea(long id, byte[] heap_area, int offset, int length)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
capacity()
Returns the capacity of the area.void
checkOut()
Checks out all changes made to this area.private int
checkPositionBounds(int diff)
void
copyTo(AreaWriter destination, int size)
Copies 'size' bytes from the current position of this Area to the destination AreaWriter.byte
get()
void
get(byte[] buf, int off, int len)
char
getChar()
long
getID()
Returns the unique identifier that represents this area.int
getInt()
long
getLong()
short
getShort()
int
position()
Returns the current position of the pointer within the area.void
position(int position)
Sets the position within the area.void
put(byte b)
void
put(byte[] buf)
void
put(byte[] buf, int off, int len)
void
putChar(char c)
void
putInt(int i)
void
putLong(long l)
void
putShort(short s)
java.lang.String
toString()
-
-
-
Field Detail
-
id
private final long id
The ID of this area.
-
heap_area
private final byte[] heap_area
A pointer to the byte[] array representing the entire area.
-
start_pointer
private final int start_pointer
The start pointer in the heap area.
-
position
private int position
The current pointer into the area.
-
end_pointer
private final int end_pointer
The end pointer of the area.
-
-
Method Detail
-
checkPositionBounds
private int checkPositionBounds(int diff) throws java.io.IOException
- Throws:
java.io.IOException
-
getID
public long getID()
Description copied from interface:Area
Returns the unique identifier that represents this area.
-
position
public int position()
Description copied from interface:Area
Returns the current position of the pointer within the area. The position starts at beginning of the area.
-
capacity
public int capacity()
Description copied from interface:Area
Returns the capacity of the area.
-
position
public void position(int position) throws java.io.IOException
Description copied from interface:Area
Sets the position within the area.
-
copyTo
public void copyTo(AreaWriter destination, int size) throws java.io.IOException
Description copied from interface:Area
Copies 'size' bytes from the current position of this Area to the destination AreaWriter.
-
get
public byte get() throws java.io.IOException
-
put
public void put(byte b) throws java.io.IOException
- Specified by:
put
in interfaceMutableArea
- Throws:
java.io.IOException
-
get
public void get(byte[] buf, int off, int len) throws java.io.IOException
-
put
public void put(byte[] buf, int off, int len) throws java.io.IOException
- Specified by:
put
in interfaceMutableArea
- Throws:
java.io.IOException
-
put
public void put(byte[] buf) throws java.io.IOException
- Specified by:
put
in interfaceMutableArea
- Throws:
java.io.IOException
-
getShort
public short getShort() throws java.io.IOException
-
putShort
public void putShort(short s) throws java.io.IOException
- Specified by:
putShort
in interfaceMutableArea
- Throws:
java.io.IOException
-
getInt
public int getInt() throws java.io.IOException
-
putInt
public void putInt(int i) throws java.io.IOException
- Specified by:
putInt
in interfaceMutableArea
- Throws:
java.io.IOException
-
getLong
public long getLong() throws java.io.IOException
-
putLong
public void putLong(long l) throws java.io.IOException
- Specified by:
putLong
in interfaceMutableArea
- Throws:
java.io.IOException
-
getChar
public char getChar() throws java.io.IOException
-
putChar
public void putChar(char c) throws java.io.IOException
- Specified by:
putChar
in interfaceMutableArea
- Throws:
java.io.IOException
-
checkOut
public void checkOut()
Description copied from interface:MutableArea
Checks out all changes made to this area. This should be called after a series of updates have been made to the area and the final change is to be 'finalized'. When this method returns, any new Area or MutableArea objects created by the backing store will contain the changes made to this object. Any changes made to the Area may or may not be made to any already existing areas.In a logging implementation, this may flush out the changes made to the area in a log.
- Specified by:
checkOut
in interfaceMutableArea
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-