Class ByteArrayConverter


  • public final class ByteArrayConverter
    extends Object
    Class to convert byte arrays (e.g., Blobs) to and from other types of arrays. TODO these could be static methods.
    Author:
    Kiran Keshav, Paul Pavlidis
    • Constructor Detail

      • ByteArrayConverter

        public ByteArrayConverter()
    • Method Detail

      • booleanArrayToBytes

        public byte[] booleanArrayToBytes​(boolean[] boolarray)
        Parameters:
        boolarray -
        Returns:
        byte[]
      • byteArrayToAsciiString

        public String byteArrayToAsciiString​(byte[] barray)
        Convert a byte array with one-byte-per-character ASCII encoding (aka ISO-8859-1).
        Parameters:
        barray -
        Returns:
      • byteArrayToBooleans

        public boolean[] byteArrayToBooleans​(byte[] barray)
        Parameters:
        barray -
        Returns:
        boolean[]
      • byteArrayToChars

        public char[] byteArrayToChars​(byte[] barray)
        Parameters:
        barray -
        Returns:
        char[]
      • byteArrayToDoubles

        public double[] byteArrayToDoubles​(byte[] barray)
        Parameters:
        barray -
        Returns:
        double[]
      • byteArrayToInts

        public int[] byteArrayToInts​(byte[] barray)
        Parameters:
        barray -
        Returns:
        int[]
      • byteArrayToLongs

        public long[] byteArrayToLongs​(byte[] barray)
        Parameters:
        barray -
        Returns:
        long[] resulting from parse of the bytes.
      • byteArrayToStrings

        public String[] byteArrayToStrings​(byte[] bytes)
        Convert a byte array into a array of Strings. It is assumed that separate strings are delimited by '' (NUL). Note that this method cannot differentiate between empty strings and null strings. A string that is empty will be returned as an empty string, not null.
        Parameters:
        bytes -
        Returns:
      • byteArrayToTabbedString

        public String byteArrayToTabbedString​(byte[] bytes,
                                              Class<?> type)
        Convert a byte array to a tab-delimited string.
        Parameters:
        bytes -
        type - The Class of primitives the bytes are to be interpreted as. If this is String, then the bytes are directly interpreted as tab-delimited string (e.g., no extra tabs are added).
        Returns:
        Throws:
        UnsupportedOperationException - if Class is a type that can't be converted by this.
      • charArrayToBytes

        public byte[] charArrayToBytes​(char[] carray)
        Parameters:
        carray -
        Returns:
        byte[]
      • doubleArrayToBytes

        public byte[] doubleArrayToBytes​(double[] darray)
        Parameters:
        darray -
        Returns:
        byte[]
      • doubleArrayToBytes

        public byte[] doubleArrayToBytes​(Double[] darray)
        Parameters:
        darray -
        Returns:
        byte[]
      • doubleArrayToBytes

        public byte[] doubleArrayToBytes​(cern.colt.list.DoubleArrayList darray)
        Parameters:
        darray -
        Returns:
      • doubleMatrixToBytes

        public byte[] doubleMatrixToBytes​(double[][] testm)
        Parameters:
        testm -
        Returns:
      • intArrayToBytes

        public byte[] intArrayToBytes​(int[] iarray)
        Parameters:
        iarray -
        Returns:
        byte[]
      • longArrayToBytes

        public byte[] longArrayToBytes​(long[] larray)
        Parameters:
        larray -
        Returns:
        byte[]
      • stringArrayToBytes

        public byte[] stringArrayToBytes​(Object[] stringArray)
        Note that this method cannot differentiate between empty strings and null strings. A string that is empty will be returned as an empty string, not null, while a null string will be stored as an empty string.
        Parameters:
        stringArray -
        Returns:
        byte[]
      • toBytes

        public byte[] toBytes​(Object data)
        Parameters:
        data -
      • toBytes

        public byte[] toBytes​(Object[] array)
        Convert an array of Objects into an array of bytes. If the array contains Strings, it is converted to a tab-delimited string, and then converted to bytes.
        Parameters:
        array - of Objects to be converted to bytes.
        Returns:
        Throws:
        UnsupportedOperationException - if Objects are a type that can't be converted by this.