Class UnsynchronizedBuffer


  • public class UnsynchronizedBuffer
    extends Object
    A utility class for reading and writing bytes to byte buffers without synchronization.
    • Constructor Detail

      • UnsynchronizedBuffer

        public UnsynchronizedBuffer()
    • Method Detail

      • nextArraySize

        public static int nextArraySize​(int i)
        Determines what next array size should be by rounding up to next power of two.
        Parameters:
        i - current array size
        Returns:
        next array size
        Throws:
        IllegalArgumentException - if i is negative
      • writeVInt

        public static void writeVInt​(DataOutput out,
                                     byte[] workBuffer,
                                     int i)
                              throws IOException
        Use the provided byte[] to buffer only the bytes used to write out the integer i to the DataOutput out. This will only ever make one write call to the DataOutput. Use this instead of WritableUtils.writeVInt(DataOutput, int) which could make up to 4 separate writes to the underlying OutputStream. Is compatible with WritableUtils as it will write the same data.
        Throws:
        IOException
      • writeVLong

        public static void writeVLong​(DataOutput out,
                                      byte[] workBuffer,
                                      long i)
                               throws IOException
        Use the provided byte[] to buffer only the bytes used to write out the long i to the DataOutput out. This will only ever make one write call to the DataOutput. Use this instead of WritableUtils.writeVLong(DataOutput, long) which could make up to 8 separate writes to the underlying OutputStream. Is compatible with WritableUtils as it will write the same data.
        Throws:
        IOException
      • writeVInt

        public static int writeVInt​(byte[] dest,
                                    int offset,
                                    int i)
        Writes a variable int directly to a byte array. Is compatible with WritableUtils as it will write the same data.
      • writeVLong

        public static int writeVLong​(byte[] dest,
                                     int offset,
                                     long value)
        Writes a variable long directly to a byte array. Is compatible with WritableUtils as it will write the same data.
        Parameters:
        dest - The destination array for the long to be written to
        offset - The location where to write the long to
        value - The long value being written into byte array
        Returns:
        Returns the new offset location