|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.bristol.star.cdf.record.BankBuf
public abstract class BankBuf
Abstract Buf implementation that divides the byte sequence into one or more contiguous data banks. Each bank contains a run of bytes short enough to be indexed by a 4-byte integer.
Nested Class Summary | |
---|---|
protected static class |
BankBuf.Bank
Data bank for use within BankBuf class and its subclasses. |
Constructor Summary | |
---|---|
protected |
BankBuf(long size,
boolean isBit64,
boolean isBigendian)
Constructor. |
Method Summary | |
---|---|
java.io.InputStream |
createInputStream(long offset)
Returns an input stream consisting of all the bytes in this buf starting from the given offset. |
static BankBuf |
createMultiBankBuf(java.nio.ByteBuffer[] byteBuffers,
boolean isBit64,
boolean isBigendian)
Returns a BankBuf based on an array of supplied ByteBuffers. |
static BankBuf |
createMultiBankBuf(java.nio.channels.FileChannel channel,
long size,
int bankSize,
boolean isBit64,
boolean isBigendian)
Returns a BankBuf based on supplied file channel. |
static BankBuf |
createSingleBankBuf(java.nio.ByteBuffer byteBuffer,
boolean isBit64,
boolean isBigendian)
Returns a BankBuf based on a single supplied ByteBuffer. |
Buf |
fillNewBuf(long count,
java.io.InputStream in)
Creates a new Buf of a given length populated from a given input stream. |
protected abstract BankBuf.Bank |
getBank(long offset,
int count)
Returns the bank which can read a given number of bytes starting at the given offset. |
protected abstract java.util.Iterator<BankBuf.Bank> |
getBankIterator(long offset)
Returns an iterator over banks starting with the one containing the given offset. |
protected abstract java.util.List<BankBuf.Bank> |
getExistingBanks()
Returns a list of active banks. |
long |
getLength()
Returns the extent of this buf in bytes. |
boolean |
isBigendian()
Determines the data encoding of this buf. |
boolean |
isBit64()
Determines the 64bit-ness of this buf. |
java.lang.String |
readAsciiString(Pointer ptr,
int nbyte)
Reads a fixed number of bytes interpreting them as ASCII characters and returns the result as a string. |
void |
readDataBytes(long offset,
int count,
byte[] array)
Reads a sequence of byte values from this buf into an array. |
void |
readDataDoubles(long offset,
int count,
double[] array)
Reads a sequence of double values from this buf into an array. |
void |
readDataFloats(long offset,
int count,
float[] array)
Reads a sequence of float values from this buf into an array. |
void |
readDataInts(long offset,
int count,
int[] array)
Reads a sequence of int values from this buf into an array. |
void |
readDataLongs(long offset,
int count,
long[] array)
Reads a sequence of long integer values from this buf into an array. |
void |
readDataShorts(long offset,
int count,
short[] array)
Reads a sequence of short values from this buf into an array. |
int |
readInt(Pointer ptr)
Reads a signed big-endian 4-byte integer from the pointer position. |
long |
readOffset(Pointer ptr)
Reads a file offset or size from the pointer position. |
int |
readUnsignedByte(Pointer ptr)
Reads a single byte from the pointer position, returning a value in the range 0..255. |
void |
setBit64(boolean isBit64)
Sets the 64bit-ness of this buf. |
void |
setEncoding(boolean bigend)
Sets the encoding for reading numeric values as performed by the readData* methods. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected BankBuf(long size, boolean isBit64, boolean isBigendian)
size
- total size of bufferisBit64
- 64bit-ness of bufisBigendian
- true for big-endian data, false for little-endianMethod Detail |
---|
protected abstract BankBuf.Bank getBank(long offset, int count) throws java.io.IOException
Implementation: in most cases this will return one of the large banks that this object has allocated. However, in the case that the requested run straddles a bank boundary it may be necessary to generate a short-lived bank just to return from this method.
offset
- start of required sequencecount
- number of bytes in required sequence
java.io.IOException
protected abstract java.util.List<BankBuf.Bank> getExistingBanks()
protected abstract java.util.Iterator<BankBuf.Bank> getBankIterator(long offset)
offset
- starting byte offset into buf
public long getLength()
Buf
getLength
in interface Buf
public int readUnsignedByte(Pointer ptr) throws java.io.IOException
Buf
readUnsignedByte
in interface Buf
ptr
- pointer
java.io.IOException
public int readInt(Pointer ptr) throws java.io.IOException
Buf
readInt
in interface Buf
ptr
- pointer
java.io.IOException
public long readOffset(Pointer ptr) throws java.io.IOException
Buf
Buf.isBit64()
.
Pointer position is moved on appropriately.
readOffset
in interface Buf
java.io.IOException
public java.lang.String readAsciiString(Pointer ptr, int nbyte) throws java.io.IOException
Buf
nbyte
bytes have
been read, it is taken as the end of the string.
Pointer position is moved on appropriately.
readAsciiString
in interface Buf
ptr
- pointernbyte
- maximum number of bytes in string
java.io.IOException
public void setBit64(boolean isBit64)
Buf
readOffset
reads
4- or 8-byte values.
This method should be called before the readOffset
method is invoked.
setBit64
in interface Buf
isBit64
- true for 8-byte offsets, false for 4-byte offsetspublic boolean isBit64()
Buf
readOffset
reads
4- or 8-byte values.
isBit64
in interface Buf
public void setEncoding(boolean bigend)
Buf
readData*
methods.
As currently specified, there are only two possibiliies, Big-Endian and Little-Endian. Interface and implementation would need to be reworked somewhat to accommodate the (presumably, rarely seen in this day and age) D_FLOAT and G_FLOAT encodings supported by the CDF standard.
This method should be called before any of the readData*
methods are invoked.
setEncoding
in interface Buf
bigend
- true for big-endian, false for little-endianpublic boolean isBigendian()
Buf
isBigendian
in interface Buf
public void readDataBytes(long offset, int count, byte[] array) throws java.io.IOException
Buf
readDataBytes
in interface Buf
offset
- position sequence start in this buffer in bytescount
- number of byte values to readarray
- array to receive values, starting at array element 0
java.io.IOException
public void readDataShorts(long offset, int count, short[] array) throws java.io.IOException
Buf
readDataShorts
in interface Buf
offset
- position sequence start in this buffer in bytescount
- number of short values to readarray
- array to receive values, starting at array element 0
java.io.IOException
public void readDataInts(long offset, int count, int[] array) throws java.io.IOException
Buf
readDataInts
in interface Buf
offset
- position sequence start in this buffer in bytescount
- number of int values to readarray
- array to receive values, starting at array element 0
java.io.IOException
public void readDataLongs(long offset, int count, long[] array) throws java.io.IOException
Buf
readDataLongs
in interface Buf
offset
- position sequence start in this buffer in bytescount
- number of long values to readarray
- array to receive values, starting at array element 0
java.io.IOException
public void readDataFloats(long offset, int count, float[] array) throws java.io.IOException
Buf
readDataFloats
in interface Buf
offset
- position sequence start in this buffer in bytescount
- number of float values to readarray
- array to receive values, starting at array element 0
java.io.IOException
public void readDataDoubles(long offset, int count, double[] array) throws java.io.IOException
Buf
readDataDoubles
in interface Buf
offset
- position sequence start in this buffer in bytescount
- number of double values to readarray
- array to receive values, starting at array element 0
java.io.IOException
public java.io.InputStream createInputStream(long offset)
Buf
createInputStream
in interface Buf
offset
- position of first byte in buf that will appear in
the returned stream
public Buf fillNewBuf(long count, java.io.InputStream in) throws java.io.IOException
Buf
fillNewBuf
in interface Buf
count
- size of new buffer in bytesin
- input stream capable of supplying
(at least) count
bytes
count
filled with bytes
from in
java.io.IOException
public static BankBuf createSingleBankBuf(java.nio.ByteBuffer byteBuffer, boolean isBit64, boolean isBigendian)
byteBuffer
- NIO buffer containing dataisBit64
- 64bit-ness of bufisBigendian
- true for big-endian data, false for little-endian
public static BankBuf createMultiBankBuf(java.nio.ByteBuffer[] byteBuffers, boolean isBit64, boolean isBigendian)
byteBuffers
- NIO buffers containing data (when concatenated)isBit64
- 64bit-ness of bufisBigendian
- true for big-endian data, false for little-endian
public static BankBuf createMultiBankBuf(java.nio.channels.FileChannel channel, long size, int bankSize, boolean isBit64, boolean isBigendian)
channel
- readable file containing datasize
- number of bytes in channelbankSize
- maximum size for individual data banksisBit64
- 64bit-ness of bufisBigendian
- true for big-endian data, false for little-endian
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |