core

## Class ByteUtils

- java.lang.Object
- - core.ByteUtils

-     public final class ByteUtils
      extends java.lang.Object

  Accommodates operations upon bytes, Bytes, bits and hexadecimal Strings, performs conversions between them, their arrays, primitives and containers.
  Author:
    David Hudec (dwdization@gmail.com)

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `private` | `ByteUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.Byte` | `bitsToByte(java.lang.String bits)` Converts a String with ones and zeros into one Byte.
    `static java.lang.Byte[]` | `bitsToBytes(java.lang.String bits)` Converts a binary String into Byte[ ].
    `static java.lang.Byte[]` | `bytesToBytes(byte[] bytes)` Converts a byte[ ] into a Byte[ ].
    `static byte[]` | `BytesTobytes(java.lang.Byte[] Bytes)` Converts a Byte[ ] into a byte[ ].
    `static java.lang.String` | `bytesToHex(java.lang.Byte b)` Transforms single Byte into hexadecimal String.
    `static java.lang.String` | `bytesToHex(java.lang.Object bytes)` Transforms byte[ ], Byte[ ] or List of Byte into their hexadecimal String representation.
    `static java.lang.String` | `byteToBits(java.lang.Byte b)` Converts a Byte into a binary String.
    `static java.lang.Byte[]` | `hexToBytes(java.lang.String s)` Transforms hexadecimal String s into array of Bytes.
    `static java.lang.Byte[]` | `hexToBytes(java.lang.String s, int length)` Transforms hexadecimal String s into array of Bytes with given length.
    `static java.lang.String` | `intToBitsWithFixedLength(int i, int length)` Converts a given int to binary String with given length.
    `static byte[]` | `listTobytes(java.util.List<java.lang.Byte> list)` Converts a List of Bytes into byte[ ].
    `static java.lang.Byte[]` | `listToBytes(java.util.List<java.lang.Byte> list)` Converts a List of Bytes into Byte[ ].
    `static java.lang.Byte[]` | `mirrorBytes(java.lang.Byte[] bytes)` Mirrors a Byte[ ], so that the first element is last and the last is first.
    `static java.lang.String` | `padBits(java.lang.String bits, int desiredLength)` Pads the given binary String with zeros until desired length is achieved.
    `static byte[]` | `padBytesToNextStep(byte[] bytes, int desLength)` Pads a byte[ ] to the next "step", which is the closest size divisible by 8 bits.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ByteUtils

          private ByteUtils()

  - ### Method Detail

    - #### bitsToByte

          public static java.lang.Byte bitsToByte(java.lang.String bits)

      Converts a String with ones and zeros into one Byte. The parameter has to be 8 bits exactly.
      Parameters:
        `bits` - binary String to convert
      Returns:
        created Byte

    - #### bitsToBytes

          public static java.lang.Byte[] bitsToBytes(java.lang.String bits)

      Converts a binary String into Byte[ ]. The resulting Byte[ ] size is bits.length()/8.
      Parameters:
        `bits` - String with ones and zeros to convert
      Returns:
        created Byte[ ]

    - #### bytesToBytes

          public static java.lang.Byte[] bytesToBytes(byte[] bytes)

      Converts a byte[ ] into a Byte[ ].
      Parameters:
        `bytes` - byte[ ] to convert
      Returns:
        created Byte[ ]

    - #### BytesTobytes

          public static byte[] BytesTobytes(java.lang.Byte[] Bytes)

      Converts a Byte[ ] into a byte[ ].
      Parameters:
        `Bytes` - Byte[ ] to convert
      Returns:
        created byte[ ]

    - #### bytesToHex

          public static java.lang.String bytesToHex(java.lang.Byte b)

      Transforms single Byte into hexadecimal String.
      Parameters:
        `b` - Byte to transform
      Returns:
        transformed String.

    - #### bytesToHex

          public static java.lang.String bytesToHex(java.lang.Object bytes)

      Transforms byte[ ], Byte[ ] or List of Byte into their hexadecimal String representation.
      Parameters:
        `bytes` - byte[ ], Byte[ ] or List of Byte object to transform
      Returns:
        transformed String
      Throws:
        `com.sun.corba.se.impl.io.TypeMismatchException` - if the parameter does not match the type restriction

    - #### byteToBits

          public static java.lang.String byteToBits(java.lang.Byte b)

      Converts a Byte into a binary String.
      Parameters:
        `b` - Byte to convert
      Returns:
        binary String representation of given Byte

    - #### hexToBytes

          public static java.lang.Byte[] hexToBytes(java.lang.String s)

      Transforms hexadecimal String s into array of Bytes. Prepends output with single '0' if necessary.
      Parameters:
        `s` - hexadecimal String to transform
      Returns:
        Byte[ ] representation of the String s

    - #### hexToBytes

          public static java.lang.Byte[] hexToBytes(java.lang.String s,
                                                    int length)

      Transforms hexadecimal String s into array of Bytes with given length. Prepends output with '0's to match the length.
      Parameters:
        `s` - hexadecimal String to transform
        `length` - desired output length
      Returns:
        Byte[ ] representation of the String s

    - #### intToBitsWithFixedLength

          public static java.lang.String intToBitsWithFixedLength(int i,
                                                                  int length)

      Converts a given int to binary String with given length. Prepends the result with zeros if needed.
      Parameters:
        `i` - int to convert
        `length` - desired length of the String
      Returns:
        binary representation of i with size of length

    - #### listTobytes

          public static byte[] listTobytes(java.util.List<java.lang.Byte> list)

      Converts a List of Bytes into byte[ ].
      Parameters:
        `list` - List of Bytes to convert
      Returns:
        created byte[ ]

    - #### listToBytes

          public static java.lang.Byte[] listToBytes(java.util.List<java.lang.Byte> list)

      Converts a List of Bytes into Byte[ ].
      Parameters:
        `list` - List of Bytes to convert
      Returns:
        created Byte[ ]

    - #### mirrorBytes

          public static java.lang.Byte[] mirrorBytes(java.lang.Byte[] bytes)

      Mirrors a Byte[ ], so that the first element is last and the last is first.
      Parameters:
        `bytes` - Byte[ ] to use for the mirroring.
      Returns:
        mirrored Byte[ ]

    - #### padBits

          public static java.lang.String padBits(java.lang.String bits,
                                                 int desiredLength)

      Pads the given binary String with zeros until desired length is achieved.
      Parameters:
        `bits` - binary String to pad
        `desiredLength` - length to aim for
      Returns:
        binary String based on the parameter with given length

    - #### padBytesToNextStep

          public static byte[] padBytesToNextStep(byte[] bytes,
                                                  int desLength)

      Pads a byte[ ] to the next "step", which is the closest size divisible by 8 bits.
      Parameters:
        `bytes` - byte[ ] to pad
        `desLength` - desired len
      Returns:
        byte[ ] based on the parameter, padded to whole number of bytes