Class DataIO


  • public class DataIO
    extends java.lang.Object
    Methods for working with Data during I/O
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.nio.charset.Charset UTF8  
      static java.lang.String UTF8_FAST  
    • Constructor Summary

      Constructors 
      Constructor Description
      DataIO()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String decodeUTF8​(java.nio.ByteBuffer in, int length)  
      static long lengthUTFv​(java.lang.String string)  
      static int lengthVnumber​(int v)  
      static int lengthVnumber​(long v)  
      static int lengthVPNnumber​(int v)  
      static int lengthVPNnumber​(long v)  
      static byte[] readByteArray​(java.io.DataInput in)  
      static int[] readIntArray​(java.io.DataInput in)  
      static int[] readIntArrayDelta​(java.io.DataInput in)  
      static long[] readLongArray​(java.io.DataInput in)  
      static long[] readLongArrayDelta​(java.io.DataInput in)  
      static long readRestOfVlong​(java.io.DataInput in, int firstByte)  
      static int readUnsignedByte​(java.io.DataInput in)  
      static java.lang.String readUTFv​(java.io.DataInput in)  
      static long readVlong​(java.io.DataInput in)  
      static int readVnumber​(java.io.DataInput in)  
      static void writeByte​(java.io.DataOutput out, int v)
      DataOutputStream writeByte with checking of argument
      static void writeByteArray​(java.io.DataOutput out, byte[] v)  
      static void writeIntArray​(java.io.DataOutput out, int[] v)
      write array preceded by its length
      static void writeIntArrayDelta​(java.io.DataOutput out, int[] v)
      Write delta encoded value, for increasing values
      static void writeLongArray​(java.io.DataOutput out, long[] v)  
      static void writeLongArrayDelta​(java.io.DataOutput out, long[] v)  
      static void writeShort​(java.io.DataOutput out, int v)
      DataOutputStream writeShort with checking of argument
      static void writeUnsignedByte​(java.io.DataOutput out, int v)
      Write lower 8 bits
      static void writeUTFv​(java.lang.String string, java.io.DataOutput out)
      Similar to writeUTF, but ok for strings > 32K bytes long and better for strings < 127 string utf-8 length must be ≤ Integer.MAX_VALUE - 1
      static void writeVnumber​(java.io.DataOutput out, int v)
      Write a positive number with the fewest bytes possible up to 127 written as a byte high order bit on means get another byte Note: value treated as unsigned 32 bit int
      static void writeVnumber​(java.io.DataOutput out, long v)
      Write a positive long with the fewest bytes possible; up to 127 written as a byte, high order bit on means get another byte.
      static void writeVPNnumber​(java.io.DataOutput out, int v)
      write a positive or negative number, optimized for fewer bytes near 0 sign put in low order bit, rest of number converted to positive and shifted left 1 max negative written as - 0.
      static void writeVPNnumber​(java.io.DataOutput out, long v)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UTF8

        public static final java.nio.charset.Charset UTF8
    • Constructor Detail

      • DataIO

        public DataIO()
    • Method Detail

      • decodeUTF8

        public static java.lang.String decodeUTF8​(java.nio.ByteBuffer in,
                                                  int length)
      • writeUTFv

        public static void writeUTFv​(java.lang.String string,
                                     java.io.DataOutput out)
                              throws java.io.IOException
        Similar to writeUTF, but ok for strings > 32K bytes long and better for strings < 127 string utf-8 length must be ≤ Integer.MAX_VALUE - 1
        Parameters:
        string - the string to write
        out - the output sink
        Throws:
        java.io.IOException - passthru
      • readUTFv

        public static java.lang.String readUTFv​(java.io.DataInput in)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • lengthUTFv

        public static long lengthUTFv​(java.lang.String string)
                               throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • writeShort

        public static void writeShort​(java.io.DataOutput out,
                                      int v)
                               throws java.io.IOException
        DataOutputStream writeShort with checking of argument
        Parameters:
        out - the output sink
        v - the value to write
        Throws:
        java.io.IOException - passthru
      • writeByte

        public static void writeByte​(java.io.DataOutput out,
                                     int v)
                              throws java.io.IOException
        DataOutputStream writeByte with checking of argument
        Parameters:
        out - output sink
        v - the value to write
        Throws:
        java.io.IOException - passthru
      • writeUnsignedByte

        public static void writeUnsignedByte​(java.io.DataOutput out,
                                             int v)
                                      throws java.io.IOException
        Write lower 8 bits
        Parameters:
        out - output sink
        v - the value to write
        Throws:
        java.io.IOException - passthru
      • writeVPNnumber

        public static void writeVPNnumber​(java.io.DataOutput out,
                                          int v)
                                   throws java.io.IOException
        write a positive or negative number, optimized for fewer bytes near 0 sign put in low order bit, rest of number converted to positive and shifted left 1 max negative written as - 0.
        Parameters:
        out - output sink
        v - the value to write
        Throws:
        java.io.IOException - passthru
      • writeVPNnumber

        public static void writeVPNnumber​(java.io.DataOutput out,
                                          long v)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • lengthVPNnumber

        public static int lengthVPNnumber​(int v)
      • lengthVPNnumber

        public static int lengthVPNnumber​(long v)
      • writeVnumber

        public static void writeVnumber​(java.io.DataOutput out,
                                        int v)
                                 throws java.io.IOException
        Write a positive number with the fewest bytes possible up to 127 written as a byte high order bit on means get another byte Note: value treated as unsigned 32 bit int
        Parameters:
        out - output sink
        v - the value to write
        Throws:
        java.io.IOException - passthru
      • lengthVnumber

        public static int lengthVnumber​(int v)
      • readVnumber

        public static int readVnumber​(java.io.DataInput in)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeVnumber

        public static void writeVnumber​(java.io.DataOutput out,
                                        long v)
                                 throws java.io.IOException
        Write a positive long with the fewest bytes possible; up to 127 written as a byte, high order bit on means get another byte.
        Parameters:
        out - output sink
        v - the value to write is never negative
        Throws:
        java.io.IOException - passthru
      • lengthVnumber

        public static int lengthVnumber​(long v)
      • readVlong

        public static long readVlong​(java.io.DataInput in)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readRestOfVlong

        public static long readRestOfVlong​(java.io.DataInput in,
                                           int firstByte)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeByteArray

        public static void writeByteArray​(java.io.DataOutput out,
                                          byte[] v)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readByteArray

        public static byte[] readByteArray​(java.io.DataInput in)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeIntArray

        public static void writeIntArray​(java.io.DataOutput out,
                                         int[] v)
                                  throws java.io.IOException
        write array preceded by its length
        Parameters:
        out - output sink
        v - the value to write
        Throws:
        java.io.IOException - passthru
      • readIntArray

        public static int[] readIntArray​(java.io.DataInput in)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeIntArrayDelta

        public static void writeIntArrayDelta​(java.io.DataOutput out,
                                              int[] v)
                                       throws java.io.IOException
        Write delta encoded value, for increasing values
        Parameters:
        out - output sink
        v - the value to write
        Throws:
        java.io.IOException - passthru
      • readIntArrayDelta

        public static int[] readIntArrayDelta​(java.io.DataInput in)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • writeLongArray

        public static void writeLongArray​(java.io.DataOutput out,
                                          long[] v)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readLongArray

        public static long[] readLongArray​(java.io.DataInput in)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeLongArrayDelta

        public static void writeLongArrayDelta​(java.io.DataOutput out,
                                               long[] v)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readLongArrayDelta

        public static long[] readLongArrayDelta​(java.io.DataInput in)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readUnsignedByte

        public static int readUnsignedByte​(java.io.DataInput in)
                                    throws java.io.IOException
        Throws:
        java.io.IOException