Class Bytes


  • public class Bytes
    extends java.lang.Object
    A wrapper class of byte array
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String HEX_PREFIX  
    • Constructor Summary

      Constructors 
      Constructor Description
      Bytes​(byte[] data)
      Creates an instance using byte array
      Bytes​(java.lang.String hexString)
      Creates an instance using hex string
      Bytes​(java.math.BigInteger value)
      Creates an instance using BigInteger
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String cleanHexPrefix​(java.lang.String input)  
      static boolean containsHexPrefix​(java.lang.String input)  
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      int length()  
      byte[] toByteArray()
      Gets the data as a byte array
      byte[] toByteArray​(int size)
      Gets the data as a byte array given size
      static byte[] toBytesPadded​(byte[] value, int length)
      add the pad bytes to the passed in block, returning the number of bytes added.
      java.lang.String toHexString​(boolean withPrefix)
      Gets the data as a hex string
      java.lang.String toHexString​(boolean withPrefix, int size)
      Gets the data as a hex string given size
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Bytes

        public Bytes​(java.lang.String hexString)
        Creates an instance using hex string
        Parameters:
        hexString - hex string of bytes
      • Bytes

        public Bytes​(byte[] data)
        Creates an instance using byte array
        Parameters:
        data - byte array to wrap
      • Bytes

        public Bytes​(java.math.BigInteger value)
        Creates an instance using BigInteger

        Set a byte array of BigInteger.toByteArray() return value. The array will contain the minimum number of bytes required to represent this BigInteger, including at least one sign bit.

        Parameters:
        value - the value
    • Method Detail

      • toByteArray

        public byte[] toByteArray()
        Gets the data as a byte array
        Returns:
        byte array
      • toBytesPadded

        public static byte[] toBytesPadded​(byte[] value,
                                           int length)
        add the pad bytes to the passed in block, returning the number of bytes added.
      • cleanHexPrefix

        public static java.lang.String cleanHexPrefix​(java.lang.String input)
      • toHexString

        public java.lang.String toHexString​(boolean withPrefix)
        Gets the data as a hex string
        Parameters:
        withPrefix - whether 0x prefix included
        Returns:
        hex string
      • containsHexPrefix

        public static boolean containsHexPrefix​(java.lang.String input)
      • toByteArray

        public byte[] toByteArray​(int size)
        Gets the data as a byte array given size
        Parameters:
        size - size of byte array
        Returns:
        byte array given size
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toHexString

        public java.lang.String toHexString​(boolean withPrefix,
                                            int size)
        Gets the data as a hex string given size
        Parameters:
        withPrefix - whether 0x prefix included
        size - size of byte array
        Returns:
        hex string given size
      • length

        public int length()