Package org.apache.accumulo.core.util
Class UnsynchronizedBuffer
- java.lang.Object
-
- org.apache.accumulo.core.util.UnsynchronizedBuffer
-
public class UnsynchronizedBuffer extends Object
A utility class for reading and writing bytes to byte buffers without synchronization.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UnsynchronizedBuffer.Reader
A byte buffer reader.static class
UnsynchronizedBuffer.Writer
A byte buffer writer.
-
Constructor Summary
Constructors Constructor Description UnsynchronizedBuffer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
nextArraySize(int i)
Determines what next array size should be by rounding up to next power of two.static int
writeVInt(byte[] dest, int offset, int i)
Writes a variable int directly to a byte array.static void
writeVInt(DataOutput out, byte[] workBuffer, int i)
Use the provided byte[] to buffer only the bytes used to write out the integer i to the DataOutput out.static int
writeVLong(byte[] dest, int offset, long value)
Writes a variable long directly to a byte array.static void
writeVLong(DataOutput out, byte[] workBuffer, long i)
Use the provided byte[] to buffer only the bytes used to write out the long i to the DataOutput out.
-
-
-
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 ofWritableUtils.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 ofWritableUtils.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 withWritableUtils
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 withWritableUtils
as it will write the same data.- Parameters:
dest
- The destination array for the long to be written tooffset
- The location where to write the long tovalue
- The long value being written into byte array- Returns:
- Returns the new offset location
-
-