Package nom.tam.fits
Class FitsHeap
- java.lang.Object
-
- nom.tam.fits.FitsHeap
-
- All Implemented Interfaces:
FitsElement
public class FitsHeap extends java.lang.Object implements FitsElement
This class supports the FITS heap. This is currently used for variable length columns in binary tables.
-
-
Field Summary
Fields Modifier and Type Field Description private BufferedDataInputStream
bstr
A stream used to read the heap dataprivate byte[]
heap
The storage bufferprivate int
heapOffset
Our current offset into the heap.private int
heapSize
The current used size of the buffer <= heap.lengthprivate static int
MINIMUM_HEAP_SIZE
-
Constructor Summary
Constructors Constructor Description FitsHeap(int size)
Create a heap of a given size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
allocate()
(package private) FitsHeap
copy()
Add a copy constructor to allow us to duplicate a heap.(package private) void
expandHeap(int need)
Check if the Heap can accommodate a given requirement.void
getData(int offset, java.lang.Object array)
Get data from the heap.long
getFileOffset()
Get the file offset of the heaplong
getSize()
Return the size of the heap using the more bean compatible format(package private) int
putData(java.lang.Object data)
Add some data to the heap.void
read(ArrayDataInput str)
Read the heapboolean
reset()
Reset the input stream to point to the beginning of this elementvoid
rewrite()
Rewrite the contents of the element in place.boolean
rewriteable()
int
size()
void
write(ArrayDataOutput str)
Write the heap
-
-
-
Field Detail
-
MINIMUM_HEAP_SIZE
private static final int MINIMUM_HEAP_SIZE
- See Also:
- Constant Field Values
-
heap
private byte[] heap
The storage buffer
-
heapSize
private int heapSize
The current used size of the buffer <= heap.length
-
heapOffset
private int heapOffset
Our current offset into the heap. When we read from the heap we use a byte array input stream. So long as we continue to read further into the heap, we can continue to use the same stream, but we need to recreate the stream whenever we skip backwards.
-
bstr
private BufferedDataInputStream bstr
A stream used to read the heap data
-
-
Method Detail
-
allocate
private void allocate()
-
copy
FitsHeap copy()
Add a copy constructor to allow us to duplicate a heap. This would be necessary if we wanted to copy an HDU that included variable length columns.
-
expandHeap
void expandHeap(int need)
Check if the Heap can accommodate a given requirement. If not expand the heap.
-
getData
public void getData(int offset, java.lang.Object array) throws FitsException
Get data from the heap.- Parameters:
offset
- The offset at which the data begins.array
- The array to be extracted.- Throws:
FitsException
- if the operation failed
-
getFileOffset
public long getFileOffset()
Get the file offset of the heap- Specified by:
getFileOffset
in interfaceFitsElement
- Returns:
- the byte at which this element begins. This is only available if the data is originally read from a random access medium.
-
getSize
public long getSize()
Return the size of the heap using the more bean compatible format- Specified by:
getSize
in interfaceFitsElement
- Returns:
- The size of this element in bytes
-
putData
int putData(java.lang.Object data) throws FitsException
Add some data to the heap.- Throws:
FitsException
-
read
public void read(ArrayDataInput str) throws FitsException
Read the heap- Specified by:
read
in interfaceFitsElement
- Parameters:
str
- The input data stream- Throws:
FitsException
- if the read was unsuccessful.
-
reset
public boolean reset()
Description copied from interface:FitsElement
Reset the input stream to point to the beginning of this element- Specified by:
reset
in interfaceFitsElement
- Returns:
- True if the reset succeeded.
-
rewrite
public void rewrite() throws java.io.IOException, FitsException
Description copied from interface:FitsElement
Rewrite the contents of the element in place. The data must have been originally read from a random access device, and the size of the element may not have changed.- Specified by:
rewrite
in interfaceFitsElement
- Throws:
java.io.IOException
- if the rewrite was unsuccessful.FitsException
- if the rewrite was unsuccessful.
-
rewriteable
public boolean rewriteable()
- Specified by:
rewriteable
in interfaceFitsElement
- Returns:
true
if this element can be rewritten?
-
size
public int size()
- Returns:
- the size of the Heap
-
write
public void write(ArrayDataOutput str) throws FitsException
Write the heap- Specified by:
write
in interfaceFitsElement
- Parameters:
str
- The data sink.- Throws:
FitsException
- if the write was unsuccessful.
-
-