Class ArrayIOUtils


  • public class ArrayIOUtils
    extends Object
    Implements functionality aiding the reading and writing in little endian of byte arrays and primitive types such as short.
    Author:
    Lyubomir Marinov
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayIOUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int readInt​(byte[] in, int inOffset)
      Reads an integer from a specific series of bytes starting the reading at a specific offset in it.
      static int readInt16​(byte[] in, int inOffset)
      Reads a short integer from a specific series of bytes starting the reading at a specific offset in it.
      static short readShort​(byte[] in, int inOffset)
      Reads a short integer from a specific series of bytes starting the reading at a specific offset in it.
      static void writeInt​(int in, byte[] out, int outOffset)
      Converts an integer to a series of bytes and writes the result into a specific output array of bytes starting the writing at a specific offset in it.
      static void writeInt16​(int in, byte[] out, int outOffset)
      Converts a short integer to a series of bytes and writes the result into a specific output array of bytes starting the writing at a specific offset in it.
      static void writeShort​(short in, byte[] out, int outOffset)
      Converts a short integer to a series of bytes and writes the result into a specific output array of bytes starting the writing at a specific offset in it.
    • Constructor Detail

      • ArrayIOUtils

        public ArrayIOUtils()
    • Method Detail

      • readInt

        public static int readInt​(byte[] in,
                                  int inOffset)
        Reads an integer from a specific series of bytes starting the reading at a specific offset in it.
        Parameters:
        in - the series of bytes to read an integer from
        inOffset - the offset in in at which the reading of the integer is to start
        Returns:
        an integer read from the specified series of bytes starting at the specified offset in it
      • readInt16

        public static int readInt16​(byte[] in,
                                    int inOffset)
        Reads a short integer from a specific series of bytes starting the reading at a specific offset in it. The difference with readShort(byte[], int) is that the read short integer is an int which has been formed by reading two bytes, not a short.
        Parameters:
        in - the series of bytes to read the short integer from
        inOffset - the offset in in at which the reading of the short integer is to start
        Returns:
        a short integer in the form of int read from the specified series of bytes starting at the specified offset in it
      • readShort

        public static short readShort​(byte[] in,
                                      int inOffset)
        Reads a short integer from a specific series of bytes starting the reading at a specific offset in it.
        Parameters:
        in - the series of bytes to read the short integer from
        inOffset - the offset in in at which the reading of the short integer is to start
        Returns:
        a short integer in the form of short read from the specified series of bytes starting at the specified offset in it
      • writeInt

        public static void writeInt​(int in,
                                    byte[] out,
                                    int outOffset)
        Converts an integer to a series of bytes and writes the result into a specific output array of bytes starting the writing at a specific offset in it.
        Parameters:
        in - the integer to be written out as a series of bytes
        out - the output to receive the conversion of the specified integer to a series of bytes
        outOffset - the offset in out at which the writing of the result of the conversion is to be started
      • writeInt16

        public static void writeInt16​(int in,
                                      byte[] out,
                                      int outOffset)
        Converts a short integer to a series of bytes and writes the result into a specific output array of bytes starting the writing at a specific offset in it. The difference with writeShort(short, byte[], int) is that the input is an int and just two bytes of it are written.
        Parameters:
        in - the short integer to be written out as a series of bytes specified as an integer i.e. the value to be converted is contained in only two of the four bytes made available by the integer
        out - the output to receive the conversion of the specified short integer to a series of bytes
        outOffset - the offset in out at which the writing of the result of the conversion is to be started
      • writeShort

        public static void writeShort​(short in,
                                      byte[] out,
                                      int outOffset)
        Converts a short integer to a series of bytes and writes the result into a specific output array of bytes starting the writing at a specific offset in it.
        Parameters:
        in - the short integer to be written out as a series of bytes specified as short
        out - the output to receive the conversion of the specified short integer to a series of bytes
        outOffset - the offset in out at which the writing of the result of the conversion is to be started