Package org.apache.iotdb.tsfile.utils
Class ReadWriteForEncodingUtils
- java.lang.Object
-
- org.apache.iotdb.tsfile.utils.ReadWriteForEncodingUtils
-
public class ReadWriteForEncodingUtils extends java.lang.ObjectUtils to read/write stream.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intgetIntMaxBitWidth(java.util.List<java.lang.Integer> list)check all number in a int list and find max bit width.static intgetLongMaxBitWidth(java.util.List<java.lang.Long> list)check all number in a long list and find max bit width.static byte[]getUnsignedVarInt(int value)transform an int var to byte[] format.static intreadIntLittleEndianPaddedOnBitWidth(java.nio.ByteBuffer buffer, int bitWidth)read integer value using special bit from input stream.static longreadLongLittleEndianPaddedOnBitWidth(java.nio.ByteBuffer buffer, int bitWidth)read long value using special bit from input stream.static intreadUnsignedVarInt(java.io.InputStream in)read an unsigned var int in stream and transform it to int format.static intreadUnsignedVarInt(java.nio.ByteBuffer buffer)read an unsigned var int in stream and transform it to int format.static intreadVarInt(java.io.InputStream in)static intreadVarInt(java.nio.ByteBuffer buffer)static intuVarIntSize(int value)Returns the encoding size in bytes of its input value.static intvarIntSize(int value)Returns the encoding size in bytes of its input value.static voidwriteIntLittleEndianPaddedOnBitWidth(int value, java.io.OutputStream out, int bitWidth)write integer value using special bit to output stream.static voidwriteLongLittleEndianPaddedOnBitWidth(long value, java.io.OutputStream out, int bitWidth)write long value using special bit to output stream.static intwriteUnsignedVarInt(int value, java.io.ByteArrayOutputStream out)write a value to stream using unsigned var int format.static intwriteUnsignedVarInt(int value, java.io.OutputStream out)static intwriteUnsignedVarInt(int value, java.nio.ByteBuffer buffer)write a value to stream using unsigned var int format.static intwriteVarInt(int value, java.io.ByteArrayOutputStream out)static intwriteVarInt(int value, java.io.OutputStream out)static intwriteVarInt(int value, java.nio.ByteBuffer buffer)
-
-
-
Method Detail
-
getIntMaxBitWidth
public static int getIntMaxBitWidth(java.util.List<java.lang.Integer> list)
check all number in a int list and find max bit width.- Parameters:
list- input list- Returns:
- max bit width
-
getLongMaxBitWidth
public static int getLongMaxBitWidth(java.util.List<java.lang.Long> list)
check all number in a long list and find max bit width.- Parameters:
list- input list- Returns:
- max bit width
-
getUnsignedVarInt
public static byte[] getUnsignedVarInt(int value)
transform an int var to byte[] format.
-
readUnsignedVarInt
public static int readUnsignedVarInt(java.io.InputStream in) throws java.io.IOExceptionread an unsigned var int in stream and transform it to int format.- Parameters:
in- stream to read an unsigned var int- Returns:
- integer value
- Throws:
java.io.IOException- exception in IO
-
readVarInt
public static int readVarInt(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
readUnsignedVarInt
public static int readUnsignedVarInt(java.nio.ByteBuffer buffer)
read an unsigned var int in stream and transform it to int format.- Parameters:
buffer- stream to read an unsigned var int- Returns:
- integer value
-
readVarInt
public static int readVarInt(java.nio.ByteBuffer buffer)
-
writeUnsignedVarInt
public static int writeUnsignedVarInt(int value, java.io.ByteArrayOutputStream out)write a value to stream using unsigned var int format. for example, int 123456789 has its binary format 00000111-01011011-11001101-00010101 (if we omit the first 5 0, then it is 111010-1101111-0011010-0010101), function writeUnsignedVarInt will split every seven bits and write them to stream from low bit to high bit like: 1-0010101 1-0011010 1-1101111 0-0111010 1 represents has next byte to write, 0 represents number end.- Parameters:
value- value to write into streamout- output stream- Returns:
- the number of bytes that the value consume.
-
writeVarInt
public static int writeVarInt(int value, java.io.ByteArrayOutputStream out)
-
writeUnsignedVarInt
public static int writeUnsignedVarInt(int value, java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
writeVarInt
public static int writeVarInt(int value, java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
writeUnsignedVarInt
public static int writeUnsignedVarInt(int value, java.nio.ByteBuffer buffer)write a value to stream using unsigned var int format. for example, int 123456789 has its binary format 111010-1101111-0011010-0010101, function writeUnsignedVarInt will split every seven bits and write them to stream from low bit to high bit like: 1-0010101 1-0011010 1-1101111 0-0111010 1 represents has next byte to write, 0 represents number end.- Parameters:
value- value to write into streambuffer- where to store the result. buffer.remaining() needs to >= 32. Notice: (1) this function does not check buffer's remaining(). (2) the position will be updated.- Returns:
- the number of bytes that the value consume.
- Throws:
java.io.IOException- exception in IO
-
writeVarInt
public static int writeVarInt(int value, java.nio.ByteBuffer buffer)
-
varIntSize
public static int varIntSize(int value)
Returns the encoding size in bytes of its input value.- Parameters:
value- the integer to be measured- Returns:
- the encoding size in bytes of its input value
-
uVarIntSize
public static int uVarIntSize(int value)
Returns the encoding size in bytes of its input value.- Parameters:
value- the unsigned integer to be measured- Returns:
- the encoding size in bytes of its input value
-
writeIntLittleEndianPaddedOnBitWidth
public static void writeIntLittleEndianPaddedOnBitWidth(int value, java.io.OutputStream out, int bitWidth) throws java.io.IOExceptionwrite integer value using special bit to output stream.- Parameters:
value- value to write to streamout- output streambitWidth- bit length- Throws:
java.io.IOException- exception in IO
-
writeLongLittleEndianPaddedOnBitWidth
public static void writeLongLittleEndianPaddedOnBitWidth(long value, java.io.OutputStream out, int bitWidth) throws java.io.IOExceptionwrite long value using special bit to output stream.- Parameters:
value- value to write to streamout- output streambitWidth- bit length- Throws:
java.io.IOException- exception in IO
-
readIntLittleEndianPaddedOnBitWidth
public static int readIntLittleEndianPaddedOnBitWidth(java.nio.ByteBuffer buffer, int bitWidth) throws java.io.IOExceptionread integer value using special bit from input stream.- Parameters:
buffer- byte bufferbitWidth- bit length- Returns:
- integer value
- Throws:
java.io.IOException- exception in IO
-
readLongLittleEndianPaddedOnBitWidth
public static long readLongLittleEndianPaddedOnBitWidth(java.nio.ByteBuffer buffer, int bitWidth) throws java.io.IOExceptionread long value using special bit from input stream.- Parameters:
buffer- byte bufferbitWidth- bit length- Returns:
- long long value
- Throws:
java.io.IOException- exception in IO
-
-