public final class Utils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static int |
bitsToInt(java.util.BitSet bits,
int start,
int length)
Takes a
BitSet and a range of bits to inspect and converts the bits
to a integer. |
static int |
bytesNeededToHoldNumber(long number)
Calculates how many bytes are needed to store the given unsigned number.
|
static int[] |
chunkIndexToChunkOffset(int chunkIndex,
int[] chunkDimensions,
int[] datasetDimensions)
Calculates the chunk offset from a given chunk index
|
static java.nio.ByteBuffer |
createSubBuffer(java.nio.ByteBuffer source,
int length)
Creates a new
ByteBuffer of the specified length. |
static int |
dimensionIndexToLinearIndex(int[] index,
int[] dimensions) |
static long |
dimensionIndexToLinearIndex(long[] index,
int[] dimensions) |
static boolean |
getBit(byte[] bytes,
int bit) |
static int[] |
linearIndexToDimensionIndex(int index,
int[] dimensions) |
static int |
readBytesAsUnsignedInt(java.nio.ByteBuffer buffer,
int length)
This reads the requested number of bytes from the buffer and returns the data
as an unsigned
int . |
static long |
readBytesAsUnsignedLong(java.nio.ByteBuffer buffer,
int length)
This reads the requested number of bytes from the buffer and returns the data
as an unsigned long.
|
static java.lang.String |
readUntilNull(java.nio.ByteBuffer buffer)
Reads ASCII string from the buffer until a null character is reached.
|
static void |
seekBufferToNextMultipleOfEight(java.nio.ByteBuffer bb)
Moves the position of the
ByteBuffer to the next position aligned on
8 bytes. |
static void |
setBit(byte[] bytes,
int bit,
boolean value) |
static int[] |
stripLeadingIndex(int[] dims)
Removes the zeroth (leading) index.
|
static java.lang.String |
toHex(long address)
Converts an address to a hex string for display
|
static boolean |
validateName(java.lang.String name)
Check the provided name to see if it is valid for a HDF5 identifier.
|
public static java.lang.String toHex(long address)
address
- to convert to Hexpublic static java.lang.String readUntilNull(java.nio.ByteBuffer buffer)
buffer
- to read fromjava.lang.IllegalArgumentException
- if the end of the buffer if reached before
and null terminatorpublic static boolean validateName(java.lang.String name)
name
- To check if validtrue
if this is a valid HDF5 name, false
otherwisepublic static void seekBufferToNextMultipleOfEight(java.nio.ByteBuffer bb)
ByteBuffer
to the next position aligned on
8 bytes. If the buffer position is already a multiple of 8 the position will
not be changed.bb
- the buffer to be alignedpublic static int readBytesAsUnsignedInt(java.nio.ByteBuffer buffer, int length)
int
. After this call the buffer position will be
advanced by the specified length.
This is used in HDF5 to read "size of lengths" and "size of offsets"
buffer
- to read fromlength
- the number of bytes to readint
value read from the bufferjava.lang.ArithmeticException
- if the data cannot be safely converted to an
unsigned int
java.lang.IllegalArgumentException
- if the length requested is not supported i.e
> 8public static long readBytesAsUnsignedLong(java.nio.ByteBuffer buffer, int length)
This is used in HDF5 to read "size of lengths" and "size of offsets"
buffer
- to read fromlength
- the number of bytes to readjava.lang.ArithmeticException
- if the data cannot be safely converted to an
unsigned longjava.lang.IllegalArgumentException
- if the length requested is not supported;public static java.nio.ByteBuffer createSubBuffer(java.nio.ByteBuffer source, int length)
ByteBuffer
of the specified length. The new buffer will
start at the current position of the source buffer and will be of the
specified length. The ByteOrder
of the new buffer will be the same as
the source buffer. After the call the source buffer position will be
incremented by the length of the sub-buffer. The new buffer will share the
backing data with the source buffer.source
- the buffer to take the sub buffer fromlength
- the size of the new sub-bufferpublic static int bitsToInt(java.util.BitSet bits, int start, int length)
BitSet
and a range of bits to inspect and converts the bits
to a integer.bits
- to inspectstart
- the first bitlength
- the number of bits to inspectpublic static int bytesNeededToHoldNumber(long number)
number
- to storejava.lang.IllegalArgumentException
- if a negative number is givenpublic static int[] linearIndexToDimensionIndex(int index, int[] dimensions)
public static int dimensionIndexToLinearIndex(int[] index, int[] dimensions)
public static long dimensionIndexToLinearIndex(long[] index, int[] dimensions)
public static int[] chunkIndexToChunkOffset(int chunkIndex, int[] chunkDimensions, int[] datasetDimensions)
chunkIndex
- The index to calculate forchunkDimensions
- The chunk dimensionsdatasetDimensions
- The dataset dimensionspublic static int[] stripLeadingIndex(int[] dims)
dims
- the array to strippublic static void setBit(byte[] bytes, int bit, boolean value)
public static boolean getBit(byte[] bytes, int bit)