Enum ByteUtils

  • All Implemented Interfaces:
    Serializable, Comparable<ByteUtils>

    public enum ByteUtils
    extends Enum<ByteUtils>
    Utility methods to do byte-level encoding. These methods are biased towards little-endian byte order because it is the most common byte order and reading several bytes at once may be optimizable in the future with the help of sun.mist.Unsafe.
    • Method Detail

      • values

        public static ByteUtils[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (ByteUtils c : ByteUtils.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static ByteUtils valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • zigZagDecode

        public static long zigZagDecode​(long n)
        Zig-zag decode.
      • zigZagEncode

        public static long zigZagEncode​(long n)
        Zig-zag encode: this helps transforming small signed numbers into small positive numbers.
      • writeLongLE

        public static void writeLongLE​(long l,
                                       byte[] arr,
                                       int offset)
        Write a long in little-endian format.
      • readLongLE

        public static long readLongLE​(byte[] arr,
                                      int offset)
        Write a long in little-endian format.
      • writeIntLE

        public static void writeIntLE​(int l,
                                      byte[] arr,
                                      int offset)
        Write an int in little-endian format.
      • readIntLE

        public static int readIntLE​(byte[] arr,
                                    int offset)
        Read an int in little-endian format.
      • writeDoubleLE

        public static void writeDoubleLE​(double d,
                                         byte[] arr,
                                         int offset)
        Write a double in little-endian format.
      • readDoubleLE

        public static double readDoubleLE​(byte[] arr,
                                          int offset)
        Read a double in little-endian format.
      • writeFloatLE

        public static void writeFloatLE​(float d,
                                        byte[] arr,
                                        int offset)
        Write a float in little-endian format.
      • readFloatLE

        public static float readFloatLE​(byte[] arr,
                                        int offset)
        Read a float in little-endian format.
      • writeVLong

        public static void writeVLong​(ByteArrayDataOutput out,
                                      long i)
        Same as DataOutput#writeVLong but accepts negative values (written on 9 bytes).
      • readVLong

        public static long readVLong​(ByteArrayDataInput in)
        Same as DataOutput#readVLong but can read negative values (read on 9 bytes).