Class Utils
- java.lang.Object
-
- org.apache.accumulo.core.file.rfile.bcfile.Utils
-
public final class Utils extends Object
Supporting Utility classes used by TFile, and shared by users of TFile.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Utils.Version
A generic Version class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
readString(DataInput in)
Read a String as a VInt n, followed by n Bytes in Text format.static int
readVInt(DataInput in)
Decoding the variable-length integer.static long
readVLong(DataInput in)
Decoding the variable-length integer.static void
writeString(DataOutput out, String s)
Write a String as a VInt n, followed by n Bytes as in Text format.static void
writeVInt(DataOutput out, int n)
Encoding an integer into a variable-length encoding format.static void
writeVLong(DataOutput out, long n)
Encoding a Long integer into a variable-length encoding format.
-
-
-
Method Detail
-
writeVInt
public static void writeVInt(DataOutput out, int n) throws IOException
Encoding an integer into a variable-length encoding format. Synonymous toUtils#writeVLong(out, n)
.- Parameters:
out
- output streamn
- The integer to be encoded- Throws:
IOException
- See Also:
writeVLong(DataOutput, long)
-
writeVLong
public static void writeVLong(DataOutput out, long n) throws IOException
Encoding a Long integer into a variable-length encoding format.- if n in [-32, 127): encode in one byte with the actual value. Otherwise,
- if n in [-20*2^8, 20*2^8): encode in two bytes: byte[0] = n/256 - 52; byte[1]=n&0xff. Otherwise,
- if n IN [-16*2^16, 16*2^16): encode in three bytes: byte[0]=n/2^16 - 88; byte[1]=(n>>8)&0xff; byte[2]=n&0xff. Otherwise,
- if n in [-8*2^24, 8*2^24): encode in four bytes: byte[0]=n/2^24 - 112; byte[1] = (n>>16)&0xff; byte[2] = (n>>8)&0xff; byte[3]=n&0xff. Otherwise:
- if n in [-2^31, 2^31): encode in five bytes: byte[0]=-125; byte[1] = (n>>24)&0xff; byte[2]=(n>>16)&0xff; byte[3]=(n>>8)&0xff; byte[4]=n&0xff;
- if n in [-2^39, 2^39): encode in six bytes: byte[0]=-124; byte[1] = (n>>32)&0xff; byte[2]=(n>>24)&0xff; byte[3]=(n>>16)&0xff; byte[4]=(n>>8)&0xff; byte[5]=n&0xff
- if n in [-2^47, 2^47): encode in seven bytes: byte[0]=-123; byte[1] = (n>>40)&0xff; byte[2]=(n>>32)&0xff; byte[3]=(n>>24)&0xff; byte[4]=(n>>16)&0xff; byte[5]=(n>>8)&0xff; byte[6]=n&0xff;
- if n in [-2^55, 2^55): encode in eight bytes: byte[0]=-122; byte[1] = (n>>48)&0xff; byte[2] = (n>>40)&0xff; byte[3]=(n>>32)&0xff; byte[4]=(n>>24)&0xff; byte[5]=(n>>16)&0xff; byte[6]=(n>>8)&0xff; byte[7]=n&0xff;
- if n in [-2^63, 2^63): encode in nine bytes: byte[0]=-121; byte[1] = (n>>54)&0xff; byte[2] = (n>>48)&0xff; byte[3] = (n>>40)&0xff; byte[4]=(n>>32)&0xff; byte[5]=(n>>24)&0xff; byte[6]=(n>>16)&0xff; byte[7]=(n>>8)&0xff; byte[8]=n&0xff;
- Parameters:
out
- output streamn
- the integer number- Throws:
IOException
-
readVInt
public static int readVInt(DataInput in) throws IOException
Decoding the variable-length integer. Synonymous to(int)Utils#readVLong(in)
.- Parameters:
in
- input stream- Returns:
- the decoded integer
- Throws:
IOException
- See Also:
readVLong(DataInput)
-
readVLong
public static long readVLong(DataInput in) throws IOException
Decoding the variable-length integer. Suppose the value of the first byte is FB, and the following bytes are NB[*].- if (FB >= -32), return (long)FB;
- if (FB in [-72, -33]), return (FB+52)<<8 + NB[0]&0xff;
- if (FB in [-104, -73]), return (FB+88)<<16 + (NB[0]&0xff)<<8 + NB[1]&0xff;
- if (FB in [-120, -105]), return (FB+112)<<24 + (NB[0]&0xff)<<16 + (NB[1]&0xff)<<8 + NB[2]&0xff;
- if (FB in [-128, -121]), return interpret NB[FB+129] as a signed big-endian integer.
- Parameters:
in
- input stream- Returns:
- the decoded long integer.
- Throws:
IOException
-
writeString
public static void writeString(DataOutput out, String s) throws IOException
Write a String as a VInt n, followed by n Bytes as in Text format.- Throws:
IOException
-
readString
public static String readString(DataInput in) throws IOException
Read a String as a VInt n, followed by n Bytes in Text format.- Parameters:
in
- The input stream.- Returns:
- The string
- Throws:
IOException
-
-