Class IOUtils


  • public class IOUtils
    extends Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char[] hexchars  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int compareBytes​(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)
      Lexicographic order of binary data.
      static int getVIntSize​(long i)
      Get the encoded length if an integer is stored in a variable-length format
      static double readDouble​(byte[] bytes, int start)
      Parse a double from a byte array.
      static float readFloat​(byte[] bytes, int start)
      Parse a float from a byte array.
      static int readVInt​(byte[] bytes, int start)
      Reads a zero-compressed encoded integer from a byte array and returns it.
      static int readVInt​(DataInput in)
      Reads a zero-compressed encoded integer from a stream and returns it.
      static long readVLong​(byte[] bytes, int start)
      Reads a zero-compressed encoded long from a byte array and returns it.
      static long readVLong​(DataInput in)
      Reads a zero-compressed encoded long from a stream and return it.
      static void writeVInt​(DataOutput stream, int i)
      Serializes an int to a binary stream with zero-compressed encoding.
      static void writeVLong​(DataOutput stream, long i)
      Serializes a long to a binary stream with zero-compressed encoding.
    • Field Detail

      • hexchars

        public static final char[] hexchars
    • Method Detail

      • readFloat

        public static float readFloat​(byte[] bytes,
                                      int start)
        Parse a float from a byte array.
      • readDouble

        public static double readDouble​(byte[] bytes,
                                        int start)
        Parse a double from a byte array.
      • readVLong

        public static long readVLong​(byte[] bytes,
                                     int start)
                              throws IOException
        Reads a zero-compressed encoded long from a byte array and returns it.
        Parameters:
        bytes - byte array with decode long
        start - starting index
        Returns:
        deserialized long
        Throws:
        IOException
      • readVInt

        public static int readVInt​(byte[] bytes,
                                   int start)
                            throws IOException
        Reads a zero-compressed encoded integer from a byte array and returns it.
        Parameters:
        bytes - byte array with the encoded integer
        start - start index
        Returns:
        deserialized integer
        Throws:
        IOException
      • readVLong

        public static long readVLong​(DataInput in)
                              throws IOException
        Reads a zero-compressed encoded long from a stream and return it.
        Parameters:
        in - input stream
        Returns:
        deserialized long
        Throws:
        IOException
      • readVInt

        public static int readVInt​(DataInput in)
                            throws IOException
        Reads a zero-compressed encoded integer from a stream and returns it.
        Parameters:
        in - input stream
        Returns:
        deserialized integer
        Throws:
        IOException
      • getVIntSize

        public static int getVIntSize​(long i)
        Get the encoded length if an integer is stored in a variable-length format
        Returns:
        the encoded length
      • writeVLong

        public static void writeVLong​(DataOutput stream,
                                      long i)
                               throws IOException
        Serializes a long to a binary stream with zero-compressed encoding. For -112 <= i <= 127, only one byte is used with the actual value. For other values of i, the first byte value indicates whether the long is positive or negative, and the number of bytes that follow. If the first byte value v is between -113 and -120, the following long is positive, with number of bytes that follow are -(v+112). If the first byte value v is between -121 and -128, the following long is negative, with number of bytes that follow are -(v+120). Bytes are stored in the high-non-zero-byte-first order.
        Parameters:
        stream - Binary output stream
        i - Long to be serialized
        Throws:
        IOException
      • writeVInt

        public static void writeVInt​(DataOutput stream,
                                     int i)
                              throws IOException
        Serializes an int to a binary stream with zero-compressed encoding.
        Parameters:
        stream - Binary output stream
        i - int to be serialized
        Throws:
        IOException
      • compareBytes

        public static int compareBytes​(byte[] b1,
                                       int s1,
                                       int l1,
                                       byte[] b2,
                                       int s2,
                                       int l2)
        Lexicographic order of binary data.