Class ZipEightByteInteger

  • All Implemented Interfaces:
    java.io.Serializable

    public final class ZipEightByteInteger
    extends java.lang.Object
    implements java.io.Serializable
    Utility class that represents an eight byte integer with conversion rules for the little-endian byte order of ZIP files.
    Since:
    1.2
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static int BYTES
      The number of bytes used to represent an instance in binary form.
      private static java.math.BigInteger HIGHEST_BIT  
      private static long serialVersionUID  
      private long value
      The value is treated as unsigned.
      static ZipEightByteInteger ZERO
      Constant for a value of zero.
    • Constructor Summary

      Constructors 
      Constructor Description
      ZipEightByteInteger​(byte[] bytes)
      Constructs a new instance from bytes.
      ZipEightByteInteger​(byte[] bytes, int offset)
      Constructs a new instance from the eight bytes starting at offset.
      ZipEightByteInteger​(long value)
      Constructs a new instance from a number.
      ZipEightByteInteger​(java.math.BigInteger value)
      Constructs a new instance from a number.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)
      Override to make two instances with same value equal.
      byte[] getBytes()
      Gets value as eight bytes in big-endian byte order.
      static byte[] getBytes​(long value)
      Gets value as eight bytes in big-endian byte order.
      static byte[] getBytes​(java.math.BigInteger value)
      Gets value as eight bytes in big-endian byte order.
      long getLongValue()
      Gets value as Java long.
      static long getLongValue​(byte[] bytes)
      Gets the value as a Java long from an eight-byte array.
      static long getLongValue​(byte[] bytes, int offset)
      Gets the value as a Java long from eight bytes starting at given array offset.
      java.math.BigInteger getValue()
      Gets value as Java BigInteger.
      static java.math.BigInteger getValue​(byte[] bytes)
      Gets the value as a Java long from an eight-byte array.
      static java.math.BigInteger getValue​(byte[] bytes, int offset)
      Gets the value as a Java BigInteger from eight bytes starting at given array offset.
      int hashCode()
      Override to make two instances with same value equal.
      java.lang.String toString()  
      (package private) static java.math.BigInteger toUnsignedBigInteger​(long value)
      package private for tests only.
      • Methods inherited from class java.lang.Object

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

      • BYTES

        static final int BYTES
        The number of bytes used to represent an instance in binary form.
        See Also:
        Constant Field Values
      • HIGHEST_BIT

        private static final java.math.BigInteger HIGHEST_BIT
      • value

        private final long value
        The value is treated as unsigned.
    • Constructor Detail

      • ZipEightByteInteger

        public ZipEightByteInteger​(java.math.BigInteger value)
        Constructs a new instance from a number.
        Parameters:
        value - the BigInteger to store as a ZipEightByteInteger
      • ZipEightByteInteger

        public ZipEightByteInteger​(byte[] bytes)
        Constructs a new instance from bytes.
        Parameters:
        bytes - the bytes to store as a ZipEightByteInteger.
      • ZipEightByteInteger

        public ZipEightByteInteger​(byte[] bytes,
                                   int offset)
        Constructs a new instance from the eight bytes starting at offset.
        Parameters:
        bytes - the bytes to store as a ZipEightByteInteger.
        offset - the offset to start.
      • ZipEightByteInteger

        public ZipEightByteInteger​(long value)
        Constructs a new instance from a number.
        Parameters:
        value - the long to store as a ZipEightByteInteger.
    • Method Detail

      • getBytes

        public static byte[] getBytes​(java.math.BigInteger value)
        Gets value as eight bytes in big-endian byte order.
        Parameters:
        value - the value to convert.
        Returns:
        value as eight bytes in big-endian byte order.
      • getBytes

        public static byte[] getBytes​(long value)
        Gets value as eight bytes in big-endian byte order.
        Parameters:
        value - the value to convert.
        Returns:
        value as eight bytes in big-endian byte order.
      • getLongValue

        public static long getLongValue​(byte[] bytes)
        Gets the value as a Java long from an eight-byte array.
        Parameters:
        bytes - the array of bytes.
        Returns:
        the corresponding Java long value.
      • getLongValue

        public static long getLongValue​(byte[] bytes,
                                        int offset)
        Gets the value as a Java long from eight bytes starting at given array offset.
        Parameters:
        bytes - the array of bytes.
        offset - the offset to start.
        Returns:
        the corresponding Java long value.
      • getValue

        public static java.math.BigInteger getValue​(byte[] bytes)
        Gets the value as a Java long from an eight-byte array.
        Parameters:
        bytes - the array of bytes.
        Returns:
        the corresponding Java BigInteger value.
      • getValue

        public static java.math.BigInteger getValue​(byte[] bytes,
                                                    int offset)
        Gets the value as a Java BigInteger from eight bytes starting at given array offset.
        Parameters:
        bytes - the array of bytes.
        offset - the offset to start.
        Returns:
        the corresponding Java BigInteger value.
      • toUnsignedBigInteger

        static java.math.BigInteger toUnsignedBigInteger​(long value)
        package private for tests only.
      • equals

        public boolean equals​(java.lang.Object o)
        Override to make two instances with same value equal.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - an object to compare.
        Returns:
        true if the objects are equal.
      • getBytes

        public byte[] getBytes()
        Gets value as eight bytes in big-endian byte order.
        Returns:
        value as eight bytes in big-endian order.
      • getLongValue

        public long getLongValue()
        Gets value as Java long.
        Returns:
        value as a long.
      • getValue

        public java.math.BigInteger getValue()
        Gets value as Java BigInteger.
        Returns:
        value as a BigInteger.
      • hashCode

        public int hashCode()
        Override to make two instances with same value equal.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code of the value stored in the ZipEightByteInteger.
      • toString

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