Package org.apache.iotdb.tsfile.utils
Class ReadWriteIOUtils
- java.lang.Object
-
- org.apache.iotdb.tsfile.utils.ReadWriteIOUtils
-
public class ReadWriteIOUtils extends Object
ConverterUtils is a utility class. It provides conversion between normal datatype and byte array.
-
-
Field Summary
Fields Modifier and Type Field Description static floatBIT_LENstatic intBOOLEAN_LENstatic intDOUBLE_LENstatic intFLOAT_LENstatic intINT_LENstatic intLONG_LENstatic intSHORT_LEN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckIfMagicString(InputStream inputStream)to check whether the inputStream is reach the magic string this method doesn't change the position of the inputStreamstatic booleancheckIfMagicString(ByteBuffer byteBuffer)to check whether the byte buffer is reach the magic string this method doesn't change the position of the byte bufferstatic ByteBufferclone(ByteBuffer original)static ByteBuffergetByteBuffer(boolean i)static ByteBuffergetByteBuffer(double d)static ByteBuffergetByteBuffer(float f)static ByteBuffergetByteBuffer(int i)static ByteBuffergetByteBuffer(long n)static ByteBuffergetByteBuffer(String s)static intread(ByteBuffer buffer)read an unsigned byte(0 ~ 255) as InputStream does.static intreadAsPossible(TsFileInput input, long position, ByteBuffer buffer)read bytes from buffer with offset position to the end of buffer.static intreadAsPossible(TsFileInput input, ByteBuffer buffer)read util to the end of buffer.static intreadAsPossible(TsFileInput input, ByteBuffer target, long offset, int len)read bytes from buffer with offset position to the end of buffer or up to len.static BinaryreadBinary(InputStream inputStream)static BinaryreadBinary(ByteBuffer buffer)static booleanreadBool(InputStream inputStream)read a bool from inputStream.static booleanreadBool(ByteBuffer buffer)read a bool from byteBuffer.static booleanreadBoolean(InputStream inputStream)static BooleanreadBoolObject(InputStream inputStream)read a Boolean from byteBuffer.static BooleanreadBoolObject(ByteBuffer buffer)read a Boolean from byteBuffer.static bytereadByte(InputStream inputStream)read a byte var from inputStream.static bytereadByte(ByteBuffer buffer)read a byte from byteBuffer.static byte[]readByteBufferWithSelfDescriptionLength(ByteBuffer buffer)read bytes from byteBuffer, this method makes sure that you can read length bytes or reach to the end of the buffer.static byte[]readBytes(InputStream inputStream, int length)unlike InputStream.read(bytes), this method makes sure that you can read length bytes or reach to the end of the stream.static byte[]readBytes(ByteBuffer buffer, int size)read bytes array in given sizestatic byte[]readBytesWithSelfDescriptionLength(InputStream inputStream)unlike InputStream.read(bytes), this method makes sure that you can read length bytes or reach to the end of the stream.static CompressionTypereadCompressionType(InputStream inputStream)static CompressionTypereadCompressionType(ByteBuffer buffer)static TSDataTypereadDataType(InputStream inputStream)static TSDataTypereadDataType(ByteBuffer buffer)static doublereadDouble(InputStream inputStream)read a double var from inputStream.static doublereadDouble(ByteBuffer byteBuffer)read a double var from byteBuffer.static TSEncodingreadEncoding(InputStream inputStream)static TSEncodingreadEncoding(ByteBuffer buffer)static floatreadFloat(InputStream inputStream)read a float var from inputStream.static floatreadFloat(ByteBuffer byteBuffer)read a float var from byteBuffer.static intreadInt(InputStream inputStream)read a int var from inputStream.static intreadInt(ByteBuffer buffer)read a int var from byteBuffer.static Set<Integer>readIntegerSet(ByteBuffer buffer)read integer set with self define length.static booleanreadIsNull(InputStream inputStream)read a bool from byteBuffer.static booleanreadIsNull(ByteBuffer buffer)read a bool from byteBuffer.static LinkedHashMap<String,String>readLinkedHashMap(ByteBuffer buffer)static longreadLong(InputStream inputStream)read a long var from inputStream.static longreadLong(ByteBuffer buffer)read a long var from byteBuffer.static Map<String,String>readMap(InputStream inputStream)static Map<String,String>readMap(ByteBuffer buffer)static List<Map<String,String>>readMaps(ByteBuffer buffer, int totalSize)static ObjectreadObject(ByteBuffer buffer)static shortreadShort(InputStream inputStream)read a short var from inputStream.static shortreadShort(ByteBuffer buffer)read a short var from byteBuffer.static StringreadString(InputStream inputStream)read string from inputStream.static StringreadString(ByteBuffer buffer)read string from byteBuffer.static StringreadStringFromDirectByteBuffer(ByteBuffer buffer)static List<String>readStringList(InputStream inputStream)read string list with self define length.static List<String>readStringList(ByteBuffer buffer)read string list with self define length.static StringreadStringWithLength(ByteBuffer buffer, int length)read string from byteBuffer with user define length.static StringreadVarIntString(InputStream inputStream)string length's type is varIntstatic StringreadVarIntString(ByteBuffer buffer)string length's type is varIntstatic intsizeToWrite(String s)static intsizeToWrite(Binary n)static voidskip(InputStream inputStream, long n)The skip method of will return only if skipping n bytes or reaching end of file.static intwrite(byte n, OutputStream outputStream)write a byte n.static intwrite(byte n, ByteBuffer buffer)write a byte n to byteBuffer.static intwrite(double n, OutputStream outputStream)write a double n to outputStream.static intwrite(double n, ByteBuffer buffer)write a double n to byteBuffer.static intwrite(float n, OutputStream outputStream)write a float n to outputStream.static intwrite(float n, ByteBuffer buffer)write a float n to byteBuffer.static intwrite(int n, OutputStream outputStream)write a int n to outputStream.static intwrite(int n, ByteBuffer buffer)write a int n to byteBuffer.static intwrite(long n, OutputStream outputStream)write a long n to outputStream.static intwrite(long n, ByteBuffer buffer)write a long n to byteBuffer.static intwrite(short n, OutputStream outputStream)write a short n.static intwrite(short n, ByteBuffer buffer)write a short n to byteBuffer.static intwrite(Boolean flag, OutputStream outputStream)write a int value to outputStream according to flag.static intwrite(Boolean flag, ByteBuffer buffer)write a byte to byteBuffer according to flag.static intwrite(String s, OutputStream outputStream)write string to outputStream.static intwrite(String s, ByteBuffer buffer)write string to byteBuffer.static intwrite(ByteBuffer byteBuffer, OutputStream outputStream)write byteBuffer.capacity and byteBuffer.array to outputStream.static intwrite(ByteBuffer byteBuffer, ByteBuffer buffer)write byteBuffer.capacity and byteBuffer.array to byteBuffer.static voidwrite(List<Map<String,String>> maps, OutputStream stream)static voidwrite(List<Map<String,String>> maps, ByteBuffer buffer)static intwrite(Map<String,String> map, OutputStream stream)static intwrite(Map<String,String> map, ByteBuffer buffer)static intwrite(CompressionType compressionType, OutputStream outputStream)CompressionType.static intwrite(CompressionType compressionType, ByteBuffer buffer)write compressionType to byteBuffer.static intwrite(TSDataType dataType, OutputStream outputStream)TSDataType.static intwrite(TSDataType dataType, ByteBuffer buffer)static intwrite(TSEncoding encoding, OutputStream outputStream)TSEncoding.static intwrite(TSEncoding encoding, ByteBuffer buffer)static intwrite(Binary binary, OutputStream outputStream)write the size (int) of the binary and then the bytes in binarystatic intwrite(Binary n, ByteBuffer buffer)write a short n to byteBuffer.static voidwriteIntegerSet(Set<Integer> set, OutputStream outputStream)write integer set with self define length.static voidwriteObject(Object value, DataOutputStream outputStream)static voidwriteObject(Object value, ByteBuffer byteBuffer)static voidwriteStringList(List<String> list, OutputStream outputStream)write string list with self define length.static voidwriteStringList(List<String> list, ByteBuffer buffer)write string list with self define length.static intwriteVar(String s, OutputStream outputStream)write string to outputStream.static intwriteVar(String s, ByteBuffer buffer)static voidwriteWithoutSize(ByteBuffer byteBuffer, int offset, int len, OutputStream outputStream)
-
-
-
Field Detail
-
BOOLEAN_LEN
public static final int BOOLEAN_LEN
- See Also:
- Constant Field Values
-
SHORT_LEN
public static final int SHORT_LEN
- See Also:
- Constant Field Values
-
INT_LEN
public static final int INT_LEN
- See Also:
- Constant Field Values
-
LONG_LEN
public static final int LONG_LEN
- See Also:
- Constant Field Values
-
DOUBLE_LEN
public static final int DOUBLE_LEN
- See Also:
- Constant Field Values
-
FLOAT_LEN
public static final int FLOAT_LEN
- See Also:
- Constant Field Values
-
BIT_LEN
public static final float BIT_LEN
- See Also:
- Constant Field Values
-
-
Method Detail
-
readBool
public static boolean readBool(InputStream inputStream) throws IOException
read a bool from inputStream.- Throws:
IOException
-
readBoolean
public static boolean readBoolean(InputStream inputStream) throws IOException
- Throws:
IOException
-
readBool
public static boolean readBool(ByteBuffer buffer)
read a bool from byteBuffer.
-
readBoolObject
public static Boolean readBoolObject(ByteBuffer buffer)
read a Boolean from byteBuffer.
-
readBoolObject
public static Boolean readBoolObject(InputStream inputStream) throws IOException
read a Boolean from byteBuffer.- Throws:
IOException
-
readByte
public static byte readByte(ByteBuffer buffer)
read a byte from byteBuffer.
-
readBytes
public static byte[] readBytes(ByteBuffer buffer, int size)
read bytes array in given size- Parameters:
buffer- buffersize- size- Returns:
- bytes array
-
readIsNull
public static boolean readIsNull(InputStream inputStream) throws IOException
read a bool from byteBuffer.- Throws:
IOException
-
readIsNull
public static boolean readIsNull(ByteBuffer buffer)
read a bool from byteBuffer.
-
write
public static int write(Map<String,String> map, OutputStream stream) throws IOException
- Throws:
IOException
-
write
public static void write(List<Map<String,String>> maps, OutputStream stream) throws IOException
- Throws:
IOException
-
write
public static int write(Map<String,String> map, ByteBuffer buffer)
-
write
public static void write(List<Map<String,String>> maps, ByteBuffer buffer)
-
write
public static int write(Boolean flag, OutputStream outputStream) throws IOException
write a int value to outputStream according to flag. If flag is true, write 1, else write 0.- Throws:
IOException
-
write
public static int write(Boolean flag, ByteBuffer buffer)
write a byte to byteBuffer according to flag. If flag is true, write 1, else write 0.
-
write
public static int write(byte n, OutputStream outputStream) throws IOExceptionwrite a byte n.- Returns:
- The number of bytes used to represent a
bytevalue in two's complement binary form. - Throws:
IOException
-
write
public static int write(short n, OutputStream outputStream) throws IOExceptionwrite a short n.- Returns:
- The number of bytes used to represent n.
- Throws:
IOException
-
write
public static int write(byte n, ByteBuffer buffer)write a byte n to byteBuffer.- Returns:
- The number of bytes used to represent a
bytevalue in two's complement binary form.
-
write
public static int write(short n, ByteBuffer buffer)write a short n to byteBuffer.- Returns:
- The number of bytes used to represent n.
-
write
public static int write(Binary n, ByteBuffer buffer)
write a short n to byteBuffer.- Returns:
- The number of bytes used to represent n.
-
write
public static int write(int n, OutputStream outputStream) throws IOExceptionwrite a int n to outputStream.- Returns:
- The number of bytes used to represent n.
- Throws:
IOException
-
write
public static int write(Binary binary, OutputStream outputStream) throws IOException
write the size (int) of the binary and then the bytes in binary- Throws:
IOException
-
write
public static int write(int n, ByteBuffer buffer)write a int n to byteBuffer.- Returns:
- The number of bytes used to represent n.
-
write
public static int write(float n, OutputStream outputStream) throws IOExceptionwrite a float n to outputStream.- Returns:
- The number of bytes used to represent n.
- Throws:
IOException
-
write
public static int write(double n, OutputStream outputStream) throws IOExceptionwrite a double n to outputStream.- Returns:
- The number of bytes used to represent n.
- Throws:
IOException
-
write
public static int write(long n, OutputStream outputStream) throws IOExceptionwrite a long n to outputStream.- Returns:
- The number of bytes used to represent n.
- Throws:
IOException
-
write
public static int write(long n, ByteBuffer buffer)write a long n to byteBuffer.
-
write
public static int write(float n, ByteBuffer buffer)write a float n to byteBuffer.
-
write
public static int write(double n, ByteBuffer buffer)write a double n to byteBuffer.
-
write
public static int write(String s, OutputStream outputStream) throws IOException
write string to outputStream.- Returns:
- the length of string represented by byte[].
- Throws:
IOException
-
writeVar
public static int writeVar(String s, OutputStream outputStream) throws IOException
write string to outputStream.- Returns:
- the length of string represented by byte[].
- Throws:
IOException
-
write
public static int write(String s, ByteBuffer buffer)
write string to byteBuffer.- Returns:
- the length of string represented by byte[].
-
writeVar
public static int writeVar(String s, ByteBuffer buffer)
-
write
public static int write(ByteBuffer byteBuffer, OutputStream outputStream) throws IOException
write byteBuffer.capacity and byteBuffer.array to outputStream.- Throws:
IOException
-
writeWithoutSize
public static void writeWithoutSize(ByteBuffer byteBuffer, int offset, int len, OutputStream outputStream) throws IOException
- Throws:
IOException
-
write
public static int write(ByteBuffer byteBuffer, ByteBuffer buffer)
write byteBuffer.capacity and byteBuffer.array to byteBuffer.
-
write
public static int write(CompressionType compressionType, OutputStream outputStream) throws IOException
CompressionType.- Throws:
IOException
-
write
public static int write(CompressionType compressionType, ByteBuffer buffer)
write compressionType to byteBuffer.
-
write
public static int write(TSDataType dataType, OutputStream outputStream) throws IOException
TSDataType.- Throws:
IOException
-
write
public static int write(TSDataType dataType, ByteBuffer buffer)
-
write
public static int write(TSEncoding encoding, OutputStream outputStream) throws IOException
TSEncoding.- Throws:
IOException
-
write
public static int write(TSEncoding encoding, ByteBuffer buffer)
-
sizeToWrite
public static int sizeToWrite(Binary n)
-
sizeToWrite
public static int sizeToWrite(String s)
-
readByte
public static byte readByte(InputStream inputStream) throws IOException
read a byte var from inputStream.- Throws:
IOException
-
readShort
public static short readShort(InputStream inputStream) throws IOException
read a short var from inputStream.- Throws:
IOException
-
readShort
public static short readShort(ByteBuffer buffer)
read a short var from byteBuffer.
-
readFloat
public static float readFloat(InputStream inputStream) throws IOException
read a float var from inputStream.- Throws:
IOException
-
readFloat
public static float readFloat(ByteBuffer byteBuffer)
read a float var from byteBuffer.
-
readDouble
public static double readDouble(InputStream inputStream) throws IOException
read a double var from inputStream.- Throws:
IOException
-
readDouble
public static double readDouble(ByteBuffer byteBuffer)
read a double var from byteBuffer.
-
readInt
public static int readInt(InputStream inputStream) throws IOException
read a int var from inputStream.- Throws:
IOException
-
readInt
public static int readInt(ByteBuffer buffer)
read a int var from byteBuffer.
-
read
public static int read(ByteBuffer buffer)
read an unsigned byte(0 ~ 255) as InputStream does.- Returns:
- the byte or -1(means there is no byte to read)
-
readLong
public static long readLong(InputStream inputStream) throws IOException
read a long var from inputStream.- Throws:
IOException
-
readLong
public static long readLong(ByteBuffer buffer)
read a long var from byteBuffer.
-
readString
public static String readString(InputStream inputStream) throws IOException
read string from inputStream.- Throws:
IOException
-
readVarIntString
public static String readVarIntString(InputStream inputStream) throws IOException
string length's type is varInt- Throws:
IOException
-
readString
public static String readString(ByteBuffer buffer)
read string from byteBuffer.
-
readVarIntString
public static String readVarIntString(ByteBuffer buffer)
string length's type is varInt
-
readStringWithLength
public static String readStringWithLength(ByteBuffer buffer, int length)
read string from byteBuffer with user define length.
-
getByteBuffer
public static ByteBuffer getByteBuffer(String s)
-
getByteBuffer
public static ByteBuffer getByteBuffer(int i)
-
getByteBuffer
public static ByteBuffer getByteBuffer(long n)
-
getByteBuffer
public static ByteBuffer getByteBuffer(float f)
-
getByteBuffer
public static ByteBuffer getByteBuffer(double d)
-
getByteBuffer
public static ByteBuffer getByteBuffer(boolean i)
-
readStringFromDirectByteBuffer
public static String readStringFromDirectByteBuffer(ByteBuffer buffer) throws CharacterCodingException
- Throws:
CharacterCodingException
-
readBytes
public static byte[] readBytes(InputStream inputStream, int length) throws IOException
unlike InputStream.read(bytes), this method makes sure that you can read length bytes or reach to the end of the stream.- Throws:
IOException
-
readMap
public static Map<String,String> readMap(ByteBuffer buffer)
-
readMap
public static Map<String,String> readMap(InputStream inputStream) throws IOException
- Throws:
IOException
-
readLinkedHashMap
public static LinkedHashMap<String,String> readLinkedHashMap(ByteBuffer buffer)
-
readMaps
public static List<Map<String,String>> readMaps(ByteBuffer buffer, int totalSize)
-
readBytesWithSelfDescriptionLength
public static byte[] readBytesWithSelfDescriptionLength(InputStream inputStream) throws IOException
unlike InputStream.read(bytes), this method makes sure that you can read length bytes or reach to the end of the stream.- Throws:
IOException
-
readBinary
public static Binary readBinary(ByteBuffer buffer)
-
readBinary
public static Binary readBinary(InputStream inputStream) throws IOException
- Throws:
IOException
-
readByteBufferWithSelfDescriptionLength
public static byte[] readByteBufferWithSelfDescriptionLength(ByteBuffer buffer)
read bytes from byteBuffer, this method makes sure that you can read length bytes or reach to the end of the buffer.read a int + buffer
-
readAsPossible
public static int readAsPossible(TsFileInput input, long position, ByteBuffer buffer) throws IOException
read bytes from buffer with offset position to the end of buffer.- Throws:
IOException
-
readAsPossible
public static int readAsPossible(TsFileInput input, ByteBuffer buffer) throws IOException
read util to the end of buffer.- Throws:
IOException
-
readAsPossible
public static int readAsPossible(TsFileInput input, ByteBuffer target, long offset, int len) throws IOException
read bytes from buffer with offset position to the end of buffer or up to len.- Throws:
IOException
-
readStringList
public static List<String> readStringList(InputStream inputStream) throws IOException
read string list with self define length.- Throws:
IOException
-
readStringList
public static List<String> readStringList(ByteBuffer buffer)
read string list with self define length.
-
writeStringList
public static void writeStringList(List<String> list, ByteBuffer buffer)
write string list with self define length.
-
writeStringList
public static void writeStringList(List<String> list, OutputStream outputStream) throws IOException
write string list with self define length.- Throws:
IOException
-
readIntegerSet
public static Set<Integer> readIntegerSet(ByteBuffer buffer)
read integer set with self define length.
-
writeIntegerSet
public static void writeIntegerSet(Set<Integer> set, OutputStream outputStream) throws IOException
write integer set with self define length.- Throws:
IOException
-
readCompressionType
public static CompressionType readCompressionType(InputStream inputStream) throws IOException
- Throws:
IOException
-
readCompressionType
public static CompressionType readCompressionType(ByteBuffer buffer)
-
readDataType
public static TSDataType readDataType(InputStream inputStream) throws IOException
- Throws:
IOException
-
readDataType
public static TSDataType readDataType(ByteBuffer buffer)
-
readEncoding
public static TSEncoding readEncoding(InputStream inputStream) throws IOException
- Throws:
IOException
-
readEncoding
public static TSEncoding readEncoding(ByteBuffer buffer)
-
checkIfMagicString
public static boolean checkIfMagicString(ByteBuffer byteBuffer)
to check whether the byte buffer is reach the magic string this method doesn't change the position of the byte buffer- Parameters:
byteBuffer- byte buffer- Returns:
- whether the byte buffer is reach the magic string
-
checkIfMagicString
public static boolean checkIfMagicString(InputStream inputStream) throws IOException
to check whether the inputStream is reach the magic string this method doesn't change the position of the inputStream- Parameters:
inputStream- inputStream- Returns:
- whether the inputStream is reach the magic string
- Throws:
IOException
-
writeObject
public static void writeObject(Object value, DataOutputStream outputStream)
-
writeObject
public static void writeObject(Object value, ByteBuffer byteBuffer)
-
readObject
public static Object readObject(ByteBuffer buffer)
-
clone
public static ByteBuffer clone(ByteBuffer original)
-
skip
public static void skip(InputStream inputStream, long n) throws IOException
The skip method of will return only if skipping n bytes or reaching end of file.- Parameters:
inputStream- the inputSteam to be skipped.n- the number of bytes to be skipped.- Throws:
IOException- if the stream does not support seek, or if some other I/O error occurs.
-
-