Package de.labathome

Class BinaryTimeseries

java.lang.Object
de.labathome.BinaryTimeseries

public class BinaryTimeseries
extends java.lang.Object
This is a class to save evenly-sampled time series data in a very simple and easy-to-read format. The key idea is to simply dump a header and then the raw data values one after another into a ByteBuffer. When you want to read only a small subset of the data, you can specify a time or an index range. A scaling and an offset can be defined for the data values (e.g. from an ADC). Examples of how to use this class can be found in Examples.java.
Author:
Jonathan Schilling (jonathan.schilling@mail.de)
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static byte DTYPE_BYTE
    Identifier value for byte datatype.
    static byte DTYPE_DOUBLE
    Identifier value for double datatype.
    static byte DTYPE_FLOAT
    Identifier value for float datatype.
    static byte DTYPE_INT
    Identifier value for int datatype.
    static byte DTYPE_LONG
    Identifier value for long datatype.
    static byte DTYPE_NONE
    Identifier value used to indicate that no raw data scaling is used.
    static byte DTYPE_SHORT
    Identifier value for short datatype.
  • Constructor Summary

    Constructors 
    Constructor Description
    BinaryTimeseries()  
  • Method Summary

    Modifier and Type Method Description
    static void buildTimebase​(double[] target, double t0, double dt)
    Compute the timebase values for a given t_0 and Delta_t.
    static void buildTimebase​(int sourceOffset, double[] target, int targetOffset, int numSamples, double t0, double dt)
    Compute the timebase values for a given t_0 and Delta_t.
    static void buildTimebase​(int sourceOffset, long[] target, int targetOffset, int numSamples, long t0, long dt)
    Compute the timebase values for a given t_0 and Delta_t.
    static void buildTimebase​(long[] target, long t0, long dt)
    Compute the timebase values for a given t_0 and Delta_t.
    static java.lang.String dtypeStr​(byte dtype)
    Get a human-readable identification string for a given data type.
    static java.lang.String explainHeader​(byte[] header)
    Given 64 header bytes, generate a human-readable explanation similar to Tab.
    static int fileOffset​(int dataSize, int index)
    Compute the file offset (and buffer size when reading the file) in bytes given the size of the contained raw data type and the number of samples/index.
    static int firstIndexInside​(double t0, double dt, double t_l)
    Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l, t_u].
    static int firstIndexInside​(long t0, long dt, long t_l)
    Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l, t_u].
    static boolean hasScaling​(byte scaling_dtype)
    Check the given dtype byte to see if the given file has a value scaling or not.
    static int lastIndexInside​(double t0, double dt, double t_u)
    Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l, t_u].
    static int lastIndexInside​(long t0, long dt, long t_u)
    Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l, t_u].
    static byte[] readData_byte​(java.nio.ByteBuffer source)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a byte[] array.
    static byte[] readData_byte​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a byte[] array.
    static double[] readData_double​(java.nio.ByteBuffer source)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a double[] array.
    static double[] readData_double​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a double[] array.
    static float[] readData_float​(java.nio.ByteBuffer source)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a float[] array.
    static float[] readData_float​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a float[] array.
    static int[] readData_int​(java.nio.ByteBuffer source)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a int[] array.
    static int[] readData_int​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a int[] array.
    static long[] readData_long​(java.nio.ByteBuffer source)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a long[] array.
    static long[] readData_long​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a long[] array.
    static short[] readData_short​(java.nio.ByteBuffer source)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a short[] array.
    static short[] readData_short​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
    Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a short[] array.
    static byte readDataType​(java.nio.ByteBuffer source)
    Read the raw data type from the given source buffer.
    static boolean readEndianessOk​(java.nio.ByteBuffer source)
    Read the first short value from the source buffer and check if it was correctly read as 1.
    static byte[] readHeader​(java.nio.ByteBuffer source)
    Read the 64 byte header from the given source buffer.
    static int readNumSamples​(java.nio.ByteBuffer source)
    Read the number of samples from the given source buffer.
    static void readRawData​(java.nio.ByteBuffer source, byte[] target, int targetOffset, int numSamples)
    Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
    static void readRawData​(java.nio.ByteBuffer source, double[] target, int targetOffset, int numSamples)
    Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
    static void readRawData​(java.nio.ByteBuffer source, float[] target, int targetOffset, int numSamples)
    Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
    static void readRawData​(java.nio.ByteBuffer source, int[] target, int targetOffset, int numSamples)
    Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
    static void readRawData​(java.nio.ByteBuffer source, long[] target, int targetOffset, int numSamples)
    Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
    static void readRawData​(java.nio.ByteBuffer source, short[] target, int targetOffset, int numSamples)
    Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
    static void readReservedDummy​(java.nio.ByteBuffer source)
    Proceed with reading from the given source buffer over the bytes reserved in the header.
    static void readScalingDisabled​(java.nio.ByteBuffer source)
    Proceed with reading from the given source buffer over the bytes reserved in the header for optional scaling parameters.
    static byte readScalingFactor_byte​(java.nio.ByteBuffer source)
    Read the scaling factor from the given source buffer as byte and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
    static double readScalingFactor_double​(java.nio.ByteBuffer source)
    Read the scaling factor from the given source buffer as double.
    static float readScalingFactor_float​(java.nio.ByteBuffer source)
    Read the scaling factor from the given source buffer as float and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
    static int readScalingFactor_int​(java.nio.ByteBuffer source)
    Read the scaling factor from the given source buffer as int and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
    static long readScalingFactor_long​(java.nio.ByteBuffer source)
    Read the scaling factor from the given source buffer as long.
    static short readScalingFactor_short​(java.nio.ByteBuffer source)
    Read the scaling factor from the given source buffer as short and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
    static byte readScalingOffset_byte​(java.nio.ByteBuffer source)
    Read the scaling offset from the given source buffer as byte and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
    static double readScalingOffset_double​(java.nio.ByteBuffer source)
    Read the scaling offset from the given source buffer as double.
    static float readScalingOffset_float​(java.nio.ByteBuffer source)
    Read the scaling offset from the given source buffer as float and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
    static int readScalingOffset_int​(java.nio.ByteBuffer source)
    Read the scaling offset from the given source buffer as int and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
    static long readScalingOffset_long​(java.nio.ByteBuffer source)
    Read the scaling offset from the given source buffer as long.
    static short readScalingOffset_short​(java.nio.ByteBuffer source)
    Read the scaling offset from the given source buffer as short and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
    static byte readScalingType​(java.nio.ByteBuffer source)
    Read the scaling data type from the given source buffer.
    static double readTimeDt_double​(java.nio.ByteBuffer source)
    Read the time interval between two consecutive samples Delta_t from the given source buffer.
    static long readTimeDt_long​(java.nio.ByteBuffer source)
    Read the time interval between two consecutive samples Delta_t from the given source buffer.
    static double readTimeT0_double​(java.nio.ByteBuffer source)
    Read the reference timestamp t_0 from the given source buffer.
    static long readTimeT0_long​(java.nio.ByteBuffer source)
    Read the reference timestamp t_0 from the given source buffer.
    static byte readTimeType​(java.nio.ByteBuffer source)
    Read the timestamp data type from the source buffer.
    static void write​(java.nio.ByteBuffer target, java.lang.Object t0, java.lang.Object dt, java.lang.Object rawData)
    Create a BinaryTimeseries with the timebase parameters t0 and dt and the unscaled rawData.
    static void write​(java.nio.ByteBuffer target, java.lang.Object t0, java.lang.Object dt, java.lang.Object rawData, java.lang.Object scalingOffset, java.lang.Object scalingFactor)
    Create a BinaryTimeseries with the timebase parameters t0 and dt and the unscaled rawData and the scaling parameters scalingOffset and scalingFactor.
    static void writeData​(java.nio.ByteBuffer target, byte[] values)
    Write the raw data values into the target buffer.
    static void writeData​(java.nio.ByteBuffer target, double[] values)
    Write the raw data values into the target buffer.
    static void writeData​(java.nio.ByteBuffer target, float[] values)
    Write the raw data values into the target buffer.
    static void writeData​(java.nio.ByteBuffer target, int[] values)
    Write the raw data values into the target buffer.
    static void writeData​(java.nio.ByteBuffer target, long[] values)
    Write the raw data values into the target buffer.
    static void writeData​(java.nio.ByteBuffer target, short[] values)
    Write the raw data values into the target buffer.
    static void writeEndianessCheckValue​(java.nio.ByteBuffer target)
    Write a 1 as short to the target file.
    static void writeReservedDummy​(java.nio.ByteBuffer target)
    Write zeros for the reserved area in the header.
    static void writeScaling​(java.nio.ByteBuffer target, byte o, byte s)
    Write the scaling parameters o and s into the target buffer.
    static void writeScaling​(java.nio.ByteBuffer target, double o, double s)
    Write the scaling parameters o and s into the target buffer.
    static void writeScaling​(java.nio.ByteBuffer target, float o, float s)
    Write the scaling parameters o and s into the target buffer.
    static void writeScaling​(java.nio.ByteBuffer target, int o, int s)
    Write the scaling parameters o and s into the target buffer.
    static void writeScaling​(java.nio.ByteBuffer target, long o, long s)
    Write the scaling parameters o and s into the target buffer.
    static void writeScaling​(java.nio.ByteBuffer target, short o, short s)
    Write the scaling parameters o and s into the target buffer.
    static void writeScalingDisabled​(java.nio.ByteBuffer target)
    Write the identifier value into the target buffer that tells the reader that no scaling is available.
    static void writeTimebase​(java.nio.ByteBuffer target, double t0, double dt)
    Write the timebase parameters t0 and dt to the target buffer.
    static void writeTimebase​(java.nio.ByteBuffer target, long t0, long dt)
    Write the timebase parameters t0 and dt to the target buffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DTYPE_NONE

      public static final byte DTYPE_NONE
      Identifier value used to indicate that no raw data scaling is used.
      See Also:
      Constant Field Values
    • DTYPE_BYTE

      public static final byte DTYPE_BYTE
      Identifier value for byte datatype.
      Length: 1 Byte
      Range: -128 ... 127
      See Also:
      Constant Field Values
    • DTYPE_SHORT

      public static final byte DTYPE_SHORT
      Identifier value for short datatype.
      Length: 2 Bytes
      Range: -32768 ... 32767
      See Also:
      Constant Field Values
    • DTYPE_INT

      public static final byte DTYPE_INT
      Identifier value for int datatype.
      Length: 4 Bytes
      Range: -2147483648 ... 2147483647
      See Also:
      Constant Field Values
    • DTYPE_LONG

      public static final byte DTYPE_LONG
      Identifier value for long datatype.
      Length: 8 Bytes
      Range: -9223372036854775808 ... 9223372036854775807
      See Also:
      Constant Field Values
    • DTYPE_FLOAT

      public static final byte DTYPE_FLOAT
      Identifier value for float datatype.
      Length: 4 Bytes
      7 decimal digits
      See Also:
      Constant Field Values
    • DTYPE_DOUBLE

      public static final byte DTYPE_DOUBLE
      Identifier value for double datatype.
      Length: 8 Bytes
      16 decimal digits
      See Also:
      Constant Field Values
  • Constructor Details

  • Method Details

    • dtypeStr

      public static final java.lang.String dtypeStr​(byte dtype)
      Get a human-readable identification string for a given data type.
      Parameters:
      dtype - one of [DTYPE_NONE, DTYPE_BYTE, DTYPE_SHORT, DTYPE_INT, DTYPE_LONG, DTYPE_FLOAT, DTYPE_DOUBLE]
      Returns:
      one of ["N", "B", "S", "I", "L", "F", "D"] or "?" if it could not be identified
    • buildTimebase

      public static final void buildTimebase​(long[] target, long t0, long dt)
      Compute the timebase values for a given t_0 and Delta_t. The number of values is given by the length of the target array, into which the values are put.
      Parameters:
      target - [N] array into which to put the timebase values t_i.
      t0 - reference timestamp; will go into target[0]
      dt - time interval between two samples
    • buildTimebase

      public static final void buildTimebase​(int sourceOffset, long[] target, int targetOffset, int numSamples, long t0, long dt)
      Compute the timebase values for a given t_0 and Delta_t. All entries in target from sourceOffset up to and including sourceOffset+numSamples-1 are filled with appropriate values of the timebase.
      Parameters:
      sourceOffset - offset in the time series indices
      target - [numSamples] array into which to put the timebase values t_i
      targetOffset - index at which to put t_0 in the target array
      numSamples - number of time stamps to generate; has to greater than or equal to target.length
      t0 - reference timestamp; will go into target[targetOffset]
      dt - time interval between two consecutive samples
    • buildTimebase

      public static final void buildTimebase​(double[] target, double t0, double dt)
      Compute the timebase values for a given t_0 and Delta_t. The number of values is given by the length of the target array, into which the values are put.
      Parameters:
      target - [N] array into which to put the timebase values t_i.
      t0 - reference timestamp; will go into target[0]
      dt - time interval between two samples
    • buildTimebase

      public static final void buildTimebase​(int sourceOffset, double[] target, int targetOffset, int numSamples, double t0, double dt)
      Compute the timebase values for a given t_0 and Delta_t. All entries in target from sourceOffset up to and including sourceOffset+numSamples-1 are filled with appropriate values of the timebase.
      Parameters:
      sourceOffset - offset in the time series indices
      target - [numSamples] array into which to put the timebase values t_i
      targetOffset - index at which to put t_0 in the target array
      numSamples - number of time stamps to generate; has to greater than or equal to target.length
      t0 - reference timestamp; will go into target[targetOffset]
      dt - time interval between two consecutive samples
    • firstIndexInside

      public static final int firstIndexInside​(long t0, long dt, long t_l)
      Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l, t_u]. See also Eqn. (7) in the documentation.
      Parameters:
      t0 - reference timestamp from the file
      dt - time interval between two consecutive samples from the file
      t_l - lower boundary of the time interval to read data from
      Returns:
      first index inside the time interval [t_l, t_u]
      See Also:
      https://stackoverflow.com/questions/7139382/java-rounding-up-to-an-int-using-math-ceil
    • lastIndexInside

      public static final int lastIndexInside​(long t0, long dt, long t_u)
      Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l, t_u]. See also Eqn. (8) in the documentation.
      Parameters:
      t0 - reference timestamp from the file
      dt - time interval between two consecutive samples from the file
      t_u - upper boundary of the time interval to read data from
      Returns:
      last index inside the time interval [t_l, t_u]
    • firstIndexInside

      public static final int firstIndexInside​(double t0, double dt, double t_l)
      Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l, t_u]. See also Eqn. (5) in the documentation.
      Parameters:
      t0 - reference timestamp from the file
      dt - time interval between two consecutive samples from the file
      t_l - lower boundary of the time interval to read data from
      Returns:
      first index inside the time interval [t_l, t_u]
    • lastIndexInside

      public static final int lastIndexInside​(double t0, double dt, double t_u)
      Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l, t_u]. See also Eqn. (6) in the documentation.
      Parameters:
      t0 - reference timestamp from the file
      dt - time interval between two consecutive samples from the file
      t_u - upper boundary of the time interval to read data from
      Returns:
      last index inside the time interval [t_l, t_u]
    • fileOffset

      public static final int fileOffset​(int dataSize, int index)
      Compute the file offset (and buffer size when reading the file) in bytes given the size of the contained raw data type and the number of samples/index. These values can be obtained from first just reading the header and then continuing with reading the whole file.
      Parameters:
      dataSize - size of the raw data values in bytes
      index - sample index or number of samples in the file
      Returns:
      byte index or file size to hold the given amount of data using a BinaryTimeseries
    • explainHeader

      public static final java.lang.String explainHeader​(byte[] header)
      Given 64 header bytes, generate a human-readable explanation similar to Tab. 2 of the documentation which lists the header contents. This routine stops explaning at the first occurrence of an invalid entry.
      Parameters:
      header - [64] binary header bytes
      Returns:
      a multi-line text (\n as line separator) which tells the user about the contents of the given header info
    • writeEndianessCheckValue

      public static final void writeEndianessCheckValue​(java.nio.ByteBuffer target)
      Write a 1 as short to the target file. This is used to check if correct endianess is used in reading; wrong endianess would lead to reading this as 256.
      Parameters:
      target - buffer into which to write the time series data
    • writeTimebase

      public static final void writeTimebase​(java.nio.ByteBuffer target, long t0, long dt)
      Write the timebase parameters t0 and dt to the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      t0 - reference timestamp
      dt - time interval between two consecutive samples
    • writeTimebase

      public static final void writeTimebase​(java.nio.ByteBuffer target, double t0, double dt)
      Write the timebase parameters t0 and dt to the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      t0 - reference timestamp
      dt - time interval between two consecutive samples
    • writeScalingDisabled

      public static final void writeScalingDisabled​(java.nio.ByteBuffer target)
      Write the identifier value into the target buffer that tells the reader that no scaling is available.
      Parameters:
      target - buffer into which to write the time series data
    • writeScaling

      public static final void writeScaling​(java.nio.ByteBuffer target, byte o, byte s)
      Write the scaling parameters o and s into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      o - offset of the raw data values
      s - scaling factor of the raw data values
    • writeScaling

      public static final void writeScaling​(java.nio.ByteBuffer target, short o, short s)
      Write the scaling parameters o and s into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      o - offset of the raw data values
      s - scaling factor of the raw data values
    • writeScaling

      public static final void writeScaling​(java.nio.ByteBuffer target, int o, int s)
      Write the scaling parameters o and s into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      o - offset of the raw data values
      s - scaling factor of the raw data values
    • writeScaling

      public static final void writeScaling​(java.nio.ByteBuffer target, long o, long s)
      Write the scaling parameters o and s into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      o - offset of the raw data values
      s - scaling factor of the raw data values
    • writeScaling

      public static final void writeScaling​(java.nio.ByteBuffer target, float o, float s)
      Write the scaling parameters o and s into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      o - offset of the raw data values
      s - scaling factor of the raw data values
    • writeScaling

      public static final void writeScaling​(java.nio.ByteBuffer target, double o, double s)
      Write the scaling parameters o and s into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      o - offset of the raw data values
      s - scaling factor of the raw data values
    • writeReservedDummy

      public static final void writeReservedDummy​(java.nio.ByteBuffer target)
      Write zeros for the reserved area in the header.
      Parameters:
      target - buffer into which to write the time series data
    • writeData

      public static final void writeData​(java.nio.ByteBuffer target, byte[] values)
      Write the raw data values into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      values - raw data values; all of them will be dumped into the target buffer
    • writeData

      public static final void writeData​(java.nio.ByteBuffer target, short[] values)
      Write the raw data values into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      values - raw data values; all of them will be dumped into the target buffer
    • writeData

      public static final void writeData​(java.nio.ByteBuffer target, int[] values)
      Write the raw data values into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      values - raw data values; all of them will be dumped into the target buffer
    • writeData

      public static final void writeData​(java.nio.ByteBuffer target, long[] values)
      Write the raw data values into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      values - raw data values; all of them will be dumped into the target buffer
    • writeData

      public static final void writeData​(java.nio.ByteBuffer target, float[] values)
      Write the raw data values into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      values - raw data values; all of them will be dumped into the target buffer
    • writeData

      public static final void writeData​(java.nio.ByteBuffer target, double[] values)
      Write the raw data values into the target buffer.
      Parameters:
      target - buffer into which to write the time series data
      values - raw data values; all of them will be dumped into the target buffer
    • write

      public static final void write​(java.nio.ByteBuffer target, java.lang.Object t0, java.lang.Object dt, java.lang.Object rawData)
      Create a BinaryTimeseries with the timebase parameters t0 and dt and the unscaled rawData.
      Parameters:
      target - buffer into which to write the time series data
      t0 - reference timestamp; can be double or long
      dt - reference timestamp; can be double or long
      rawData - raw data array; can be byte[], short[], int[], long[], float[] or double[]
    • write

      public static final void write​(java.nio.ByteBuffer target, java.lang.Object t0, java.lang.Object dt, java.lang.Object rawData, java.lang.Object scalingOffset, java.lang.Object scalingFactor)
      Create a BinaryTimeseries with the timebase parameters t0 and dt and the unscaled rawData and the scaling parameters scalingOffset and scalingFactor.
      Parameters:
      target - buffer into which to write the time series data
      t0 - reference timestamp; can be double or long
      dt - reference timestamp; can be double or long
      rawData - raw data array; can be byte[], short[], int[], long[], float[] or double[]
      scalingOffset - scaling offset of the raw data to be saved into the file; can be null, byte, short, int, long, float or double
      scalingFactor - scaling factor of the raw data to be saved into the file; can be null, byte, short, int, long, float or double
    • readHeader

      public static final byte[] readHeader​(java.nio.ByteBuffer source)
      Read the 64 byte header from the given source buffer.
      Parameters:
      source - buffer from which to read the first 64 bytes
      Returns:
      the first 64 bytes as read from source
    • readEndianessOk

      public static final boolean readEndianessOk​(java.nio.ByteBuffer source)
      Read the first short value from the source buffer and check if it was correctly read as 1.
      Parameters:
      source - buffer from which to read
      Returns:
      true if the read value was 1, false if if was 256 (indicating wrong endianess of source
      Throws:
      java.lang.RuntimeException - in any case something else than 1 or 256 was read
    • readTimeType

      public static final byte readTimeType​(java.nio.ByteBuffer source)
      Read the timestamp data type from the source buffer.
      Parameters:
      source - buffer from which to read
      Returns:
      timestamp dtype; should either be DTYPE_LONG or DTYPE_DOUBLE
    • readTimeT0_long

      public static final long readTimeT0_long​(java.nio.ByteBuffer source)
      Read the reference timestamp t_0 from the given source buffer.
      Parameters:
      source - buffer from which to read
      Returns:
      reference timestamp read as long
    • readTimeDt_long

      public static final long readTimeDt_long​(java.nio.ByteBuffer source)
      Read the time interval between two consecutive samples Delta_t from the given source buffer.
      Parameters:
      source - buffer from which to read
      Returns:
      time interval between two consecutive samples Delta_t read as long
    • readTimeT0_double

      public static final double readTimeT0_double​(java.nio.ByteBuffer source)
      Read the reference timestamp t_0 from the given source buffer.
      Parameters:
      source - buffer from which to read
      Returns:
      reference timestamp read as double
    • readTimeDt_double

      public static final double readTimeDt_double​(java.nio.ByteBuffer source)
      Read the time interval between two consecutive samples Delta_t from the given source buffer.
      Parameters:
      source - buffer from which to read
      Returns:
      time interval between two consecutive samples Delta_t read as double
    • hasScaling

      public static final boolean hasScaling​(byte scaling_dtype)
      Check the given dtype byte to see if the given file has a value scaling or not.
      Parameters:
      scaling_dtype - dtype byte as read from input buffer
      Returns:
      false if the data has no scaling; true if it has scaling
    • readScalingType

      public static final byte readScalingType​(java.nio.ByteBuffer source)
      Read the scaling data type from the given source buffer.
      Parameters:
      source - buffer from which to read
      Returns:
      one of DTYPE_NONE, DTYPE_BYTE, DTYPE_SHORT, DTYPE_INT, DTYPE_LONG, DTYPE_FLOAT or DTYPE_DOUBLE
    • readScalingDisabled

      public static final void readScalingDisabled​(java.nio.ByteBuffer source)
      Proceed with reading from the given source buffer over the bytes reserved in the header for optional scaling parameters. Currently, this simply reads 16 bytes from the buffer.
      Parameters:
      source - buffer from which to read
    • readScalingOffset_byte

      public static final byte readScalingOffset_byte​(java.nio.ByteBuffer source)
      Read the scaling offset from the given source buffer as byte and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling offset read as byte
    • readScalingFactor_byte

      public static final byte readScalingFactor_byte​(java.nio.ByteBuffer source)
      Read the scaling factor from the given source buffer as byte and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling factor read as byte
    • readScalingOffset_short

      public static final short readScalingOffset_short​(java.nio.ByteBuffer source)
      Read the scaling offset from the given source buffer as short and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling offset read as short
    • readScalingFactor_short

      public static final short readScalingFactor_short​(java.nio.ByteBuffer source)
      Read the scaling factor from the given source buffer as short and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling factor read as short
    • readScalingOffset_int

      public static final int readScalingOffset_int​(java.nio.ByteBuffer source)
      Read the scaling offset from the given source buffer as int and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling offset read as int
    • readScalingFactor_int

      public static final int readScalingFactor_int​(java.nio.ByteBuffer source)
      Read the scaling factor from the given source buffer as int and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling factor read as int
    • readScalingOffset_long

      public static final long readScalingOffset_long​(java.nio.ByteBuffer source)
      Read the scaling offset from the given source buffer as long.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling offset read as long
    • readScalingFactor_long

      public static final long readScalingFactor_long​(java.nio.ByteBuffer source)
      Read the scaling factor from the given source buffer as long.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling factor read as long
    • readScalingOffset_float

      public static final float readScalingOffset_float​(java.nio.ByteBuffer source)
      Read the scaling offset from the given source buffer as float and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling offset read as float
    • readScalingFactor_float

      public static final float readScalingFactor_float​(java.nio.ByteBuffer source)
      Read the scaling factor from the given source buffer as float and proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling factor read as float
    • readScalingOffset_double

      public static final double readScalingOffset_double​(java.nio.ByteBuffer source)
      Read the scaling offset from the given source buffer as double.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling offset read as double
    • readScalingFactor_double

      public static final double readScalingFactor_double​(java.nio.ByteBuffer source)
      Read the scaling factor from the given source buffer as double.
      Parameters:
      source - buffer from which to read
      Returns:
      scaling factor read as double
    • readReservedDummy

      public static final void readReservedDummy​(java.nio.ByteBuffer source)
      Proceed with reading from the given source buffer over the bytes reserved in the header. Currently, this simply reads 23 bytes from the buffer.
      Parameters:
      source - buffer from which to read
    • readDataType

      public static final byte readDataType​(java.nio.ByteBuffer source)
      Read the raw data type from the given source buffer.
      Parameters:
      source - buffer from which to read
      Returns:
      one of DTYPE_BYTE, DTYPE_SHORT, DTYPE_INT, DTYPE_LONG, DTYPE_FLOAT or DTYPE_DOUBLE
    • readNumSamples

      public static final int readNumSamples​(java.nio.ByteBuffer source)
      Read the number of samples from the given source buffer.
      Parameters:
      source - buffer from which to read
      Returns:
      number of samples; should be > 0
    • readRawData

      public static final void readRawData​(java.nio.ByteBuffer source, byte[] target, int targetOffset, int numSamples)
      Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
      Parameters:
      source - buffer from which to read
      target - array into which to read the given samples
      targetOffset - offset in target at which to put the first sample read from the source buffer
      numSamples - number of samples to be read from the source buffer
    • readRawData

      public static final void readRawData​(java.nio.ByteBuffer source, short[] target, int targetOffset, int numSamples)
      Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
      Parameters:
      source - buffer from which to read
      target - array into which to read the given samples
      targetOffset - offset in target at which to put the first sample read from the source buffer
      numSamples - number of samples to be read from the source buffer
    • readRawData

      public static final void readRawData​(java.nio.ByteBuffer source, int[] target, int targetOffset, int numSamples)
      Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
      Parameters:
      source - buffer from which to read
      target - array into which to read the given samples
      targetOffset - offset in target at which to put the first sample read from the source buffer
      numSamples - number of samples to be read from the source buffer
    • readRawData

      public static final void readRawData​(java.nio.ByteBuffer source, long[] target, int targetOffset, int numSamples)
      Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
      Parameters:
      source - buffer from which to read
      target - array into which to read the given samples
      targetOffset - offset in target at which to put the first sample read from the source buffer
      numSamples - number of samples to be read from the source buffer
    • readRawData

      public static final void readRawData​(java.nio.ByteBuffer source, float[] target, int targetOffset, int numSamples)
      Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
      Parameters:
      source - buffer from which to read
      target - array into which to read the given samples
      targetOffset - offset in target at which to put the first sample read from the source buffer
      numSamples - number of samples to be read from the source buffer
    • readRawData

      public static final void readRawData​(java.nio.ByteBuffer source, double[] target, int targetOffset, int numSamples)
      Read the raw data from the given source buffer and put them into a given target array at an offset specified by targetOffset.
      Parameters:
      source - buffer from which to read
      target - array into which to read the given samples
      targetOffset - offset in target at which to put the first sample read from the source buffer
      numSamples - number of samples to be read from the source buffer
    • readData_byte

      public static final byte[] readData_byte​(java.nio.ByteBuffer source)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a byte[] array.
      Parameters:
      source - buffer from which to read
      Returns:
      an array containing the (scaled) data from the source buffer
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_byte

      public static final byte[] readData_byte​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a byte[] array.
      Parameters:
      source - buffer from which to read
      firstDataIndex - the index of the first sample to read from the given buffer
      lastDataIndex - the index of the last sample to read from the given buffer; -1 means read all available samples
      Returns:
      an array containing the (scaled) data from the source buffer in the range firstDataIndex up to and including lastDataIndex
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_short

      public static final short[] readData_short​(java.nio.ByteBuffer source)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a short[] array.
      Parameters:
      source - buffer from which to read
      Returns:
      an array containing the (scaled) data from the source buffer
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_short

      public static final short[] readData_short​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a short[] array.
      Parameters:
      source - buffer from which to read
      firstDataIndex - the index of the first sample to read from the given buffer
      lastDataIndex - the index of the last sample to read from the given buffer; -1 means read all available samples
      Returns:
      an array containing the (scaled) data from the source buffer in the range firstDataIndex up to and including lastDataIndex
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_int

      public static final int[] readData_int​(java.nio.ByteBuffer source)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a int[] array.
      Parameters:
      source - buffer from which to read
      Returns:
      an array containing the (scaled) data from the source buffer
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_int

      public static final int[] readData_int​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a int[] array.
      Parameters:
      source - buffer from which to read
      firstDataIndex - the index of the first sample to read from the given buffer
      lastDataIndex - the index of the last sample to read from the given buffer; -1 means read all available samples
      Returns:
      an array containing the (scaled) data from the source buffer in the range firstDataIndex up to and including lastDataIndex
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_long

      public static final long[] readData_long​(java.nio.ByteBuffer source)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a long[] array.
      Parameters:
      source - buffer from which to read
      Returns:
      an array containing the (scaled) data from the source buffer
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_long

      public static final long[] readData_long​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a long[] array.
      Parameters:
      source - buffer from which to read
      firstDataIndex - the index of the first sample to read from the given buffer
      lastDataIndex - the index of the last sample to read from the given buffer; -1 means read all available samples
      Returns:
      an array containing the (scaled) data from the source buffer in the range firstDataIndex up to and including lastDataIndex
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_float

      public static final float[] readData_float​(java.nio.ByteBuffer source)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a float[] array.
      Parameters:
      source - buffer from which to read
      Returns:
      an array containing the (scaled) data from the source buffer
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_float

      public static final float[] readData_float​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a float[] array.
      Parameters:
      source - buffer from which to read
      firstDataIndex - the index of the first sample to read from the given buffer
      lastDataIndex - the index of the last sample to read from the given buffer; -1 means read all available samples
      Returns:
      an array containing the (scaled) data from the source buffer in the range firstDataIndex up to and including lastDataIndex
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_double

      public static final double[] readData_double​(java.nio.ByteBuffer source)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a double[] array.
      Parameters:
      source - buffer from which to read
      Returns:
      an array containing the (scaled) data from the source buffer
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered
    • readData_double

      public static final double[] readData_double​(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)
      Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into a double[] array.
      Parameters:
      source - buffer from which to read
      firstDataIndex - the index of the first sample to read from the given buffer
      lastDataIndex - the index of the last sample to read from the given buffer; -1 means read all available samples
      Returns:
      an array containing the (scaled) data from the source buffer in the range firstDataIndex up to and including lastDataIndex
      Throws:
      java.lang.RuntimeException - if an unknown scaling type or data type was encountered