Package uk.ac.bristol.star.cdf.record
Class WrapperBuf
java.lang.Object
uk.ac.bristol.star.cdf.record.WrapperBuf
- All Implemented Interfaces:
Buf
Buf implementation based on an existing Buf instance.
All methods are delegated to the base buf.
- Since:
- 18 Jun 2013
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateInputStream(long offset) Returns an input stream consisting of all the bytes in this buf starting from the given offset.fillNewBuf(long count, InputStream in) Creates a new Buf of a given length populated from a given input stream.longReturns the extent of this buf in bytes.booleanDetermines the data encoding of this buf.booleanisBit64()Determines the 64bit-ness of this buf.readAsciiString(Pointer ptr, int nbyte) Reads a fixed number of bytes interpreting them as ASCII characters and returns the result as a string.voidreadDataBytes(long offset, int count, byte[] array) Reads a sequence of byte values from this buf into an array.voidreadDataDoubles(long offset, int count, double[] array) Reads a sequence of double values from this buf into an array.voidreadDataFloats(long offset, int count, float[] array) Reads a sequence of float values from this buf into an array.voidreadDataInts(long offset, int count, int[] array) Reads a sequence of int values from this buf into an array.voidreadDataLongs(long offset, int count, long[] array) Reads a sequence of long integer values from this buf into an array.voidreadDataShorts(long offset, int count, short[] array) Reads a sequence of short values from this buf into an array.intReads a signed big-endian 4-byte integer from the pointer position.longreadOffset(Pointer ptr) Reads a file offset or size from the pointer position.intreadUnsignedByte(Pointer ptr) Reads a single byte from the pointer position, returning a value in the range 0..255.voidsetBit64(boolean bit64) Sets the 64bit-ness of this buf.voidsetEncoding(boolean isBigendian) Sets the encoding for reading numeric values as performed by thereadData*methods.
-
Constructor Details
-
WrapperBuf
Constructor.- Parameters:
base- base buf
-
-
Method Details
-
getLength
public long getLength()Description copied from interface:BufReturns the extent of this buf in bytes. -
readUnsignedByte
Description copied from interface:BufReads a single byte from the pointer position, returning a value in the range 0..255. Pointer position is moved on appropriately.- Specified by:
readUnsignedBytein interfaceBuf- Parameters:
ptr- pointer- Returns:
- byte value
- Throws:
IOException
-
readInt
Description copied from interface:BufReads a signed big-endian 4-byte integer from the pointer position. Pointer position is moved on appropriately.- Specified by:
readIntin interfaceBuf- Parameters:
ptr- pointer- Returns:
- integer value
- Throws:
IOException
-
readOffset
Description copied from interface:BufReads a file offset or size from the pointer position. This is a signed big-endian integer, occupying either 4 or 8 bytes according to the return value ofBuf.isBit64(). Pointer position is moved on appropriately.- Specified by:
readOffsetin interfaceBuf- Returns:
- buffer size or offset value
- Throws:
IOException
-
readAsciiString
Description copied from interface:BufReads a fixed number of bytes interpreting them as ASCII characters and returns the result as a string. If a character 0x00 appears beforenbytebytes have been read, it is taken as the end of the string. Pointer position is moved on appropriately.- Specified by:
readAsciiStringin interfaceBuf- Parameters:
ptr- pointernbyte- maximum number of bytes in string- Returns:
- ASCII string
- Throws:
IOException
-
setBit64
public void setBit64(boolean bit64) Description copied from interface:BufSets the 64bit-ness of this buf. This determines whetherreadOffsetreads 4- or 8-byte values.This method should be called before the
readOffsetmethod is invoked. -
isBit64
public boolean isBit64()Description copied from interface:BufDetermines the 64bit-ness of this buf. This determines whetherreadOffsetreads 4- or 8-byte values. -
setEncoding
public void setEncoding(boolean isBigendian) Description copied from interface:BufSets the encoding for reading numeric values as performed by thereadData*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.- Specified by:
setEncodingin interfaceBuf- Parameters:
isBigendian- true for big-endian, false for little-endian
-
isBigendian
public boolean isBigendian()Description copied from interface:BufDetermines the data encoding of this buf.- Specified by:
isBigendianin interfaceBuf- Returns:
- true for big-endian, false for little-endian
-
readDataBytes
Description copied from interface:BufReads a sequence of byte values from this buf into an array.- Specified by:
readDataBytesin interfaceBuf- Parameters:
offset- position sequence start in this buffer in bytescount- number of byte values to readarray- array to receive values, starting at array element 0- Throws:
IOException
-
readDataShorts
Description copied from interface:BufReads a sequence of short values from this buf into an array.- Specified by:
readDataShortsin interfaceBuf- Parameters:
offset- position sequence start in this buffer in bytescount- number of short values to readarray- array to receive values, starting at array element 0- Throws:
IOException
-
readDataInts
Description copied from interface:BufReads a sequence of int values from this buf into an array.- Specified by:
readDataIntsin interfaceBuf- Parameters:
offset- position sequence start in this buffer in bytescount- number of int values to readarray- array to receive values, starting at array element 0- Throws:
IOException
-
readDataLongs
Description copied from interface:BufReads a sequence of long integer values from this buf into an array.- Specified by:
readDataLongsin interfaceBuf- Parameters:
offset- position sequence start in this buffer in bytescount- number of long values to readarray- array to receive values, starting at array element 0- Throws:
IOException
-
readDataFloats
Description copied from interface:BufReads a sequence of float values from this buf into an array.- Specified by:
readDataFloatsin interfaceBuf- Parameters:
offset- position sequence start in this buffer in bytescount- number of float values to readarray- array to receive values, starting at array element 0- Throws:
IOException
-
readDataDoubles
Description copied from interface:BufReads a sequence of double values from this buf into an array.- Specified by:
readDataDoublesin interfaceBuf- Parameters:
offset- position sequence start in this buffer in bytescount- number of double values to readarray- array to receive values, starting at array element 0- Throws:
IOException
-
createInputStream
Description copied from interface:BufReturns an input stream consisting of all the bytes in this buf starting from the given offset.- Specified by:
createInputStreamin interfaceBuf- Parameters:
offset- position of first byte in buf that will appear in the returned stream- Returns:
- input stream
-
fillNewBuf
Description copied from interface:BufCreates a new Buf of a given length populated from a given input stream. The new buf object must have the same data encoding and 64bit-ness as this one.- Specified by:
fillNewBufin interfaceBuf- Parameters:
count- size of new buffer in bytesin- input stream capable of supplying (at least)countbytes- Returns:
- new buffer of length
countfilled with bytes fromin - Throws:
IOException
-