Package org.apache.storm.utils
Class WritableUtils
java.lang.Object
org.apache.storm.utils.WritableUtils
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic intdecodeVIntSize(byte value) Parse the first byte of a vint/vlong to determine the number of bytes.static voiddisplayByteArray(byte[] record) Test Utility Method Display Byte Array.static intgetVIntSize(long i) Get the encoded length if an integer is stored in a variable-length format.static booleanisNegativeVInt(byte value) Given the first byte of a vint/vlong, determine the sign.static byte[]static StringUgly utility, maybe someone else can do this better.static String[]Write a String array as a Nework Int N, followed by Int N Byte Array Strings.static StringreadString(DataInput in) Read a String as a Network Int n, followed by n Bytes Alternative to 16 bit read/writeUTF.static String[]Write a String array as a Nework Int N, followed by Int N Byte Array Strings.static intReads a zero-compressed encoded integer from input stream and returns it.static longReads a zero-compressed encoded long from input stream and returns it.static voidstatic voidSkip len number of bytes in input streamin.static intwriteCompressedByteArray(DataOutput out, byte[] bytes) static intwriteCompressedString(DataOutput out, String s) static voidwriteCompressedStringArray(DataOutput out, String[] s) static voidwriteString(DataOutput out, String s) Write a String as a Network Int n, followed by n Bytes Alternative to 16 bit read/writeUTF.static voidwriteStringArray(DataOutput out, String[] s) Write a String array as a Nework Int N, followed by Int N Byte Array Strings.static voidwriteVInt(DataOutput stream, int i) Serializes an integer to a binary stream with zero-compressed encoding.static voidwriteVLong(DataOutput stream, long i) Serializes a long to a binary stream with zero-compressed encoding.
- 
Constructor Details- 
WritableUtilspublic WritableUtils()
 
- 
- 
Method Details- 
readCompressedByteArray- Throws:
- IOException
 
- 
skipCompressedByteArray- Throws:
- IOException
 
- 
writeCompressedByteArray- Throws:
- IOException
 
- 
readCompressedStringUgly utility, maybe someone else can do this better.- Throws:
- IOException
 
- 
writeCompressedString- Throws:
- IOException
 
- 
writeStringWrite a String as a Network Int n, followed by n Bytes Alternative to 16 bit read/writeUTF. Encoding standard is... ?- Throws:
- IOException
 
- 
readStringRead a String as a Network Int n, followed by n Bytes Alternative to 16 bit read/writeUTF. Encoding standard is... ?- Throws:
- IOException
 
- 
writeStringArrayWrite a String array as a Nework Int N, followed by Int N Byte Array Strings. Could be generalised using introspection.- Throws:
- IOException
 
- 
writeCompressedStringArray- Throws:
- IOException
 
- 
readStringArrayWrite a String array as a Nework Int N, followed by Int N Byte Array Strings. Could be generalised using introspection. Actually this bit couldn't...- Throws:
- IOException
 
- 
readCompressedStringArrayWrite a String array as a Nework Int N, followed by Int N Byte Array Strings. Could be generalised using introspection. Handles null arrays and null values.- Throws:
- IOException
 
- 
displayByteArraypublic static void displayByteArray(byte[] record) Test Utility Method Display Byte Array.
- 
writeVIntSerializes an integer to a binary stream with zero-compressed encoding. For -120 <= i <= 127, only one byte is used with the actual value. For other values of i, the first byte value indicates whether the integer is positive or negative, and the number of bytes that follow. If the first byte value v is between -121 and -124, the following integer is positive, with number of bytes that follow are -(v+120). If the first byte value v is between -125 and -128, the following integer is negative, with number of bytes that follow are -(v+124). Bytes are stored in the high-non-zero-byte-first order.- Parameters:
- stream- Binary output stream
- i- Integer to be serialized
- Throws:
- IOException
 
- 
writeVLongSerializes a long to a binary stream with zero-compressed encoding. For -112 <= i <= 127, only one byte is used with the actual value. For other values of i, the first byte value indicates whether the long is positive or negative, and the number of bytes that follow. If the first byte value v is between -113 and -120, the following long is positive, with number of bytes that follow are -(v+112). If the first byte value v is between -121 and -128, the following long is negative, with number of bytes that follow are -(v+120). Bytes are stored in the high-non-zero-byte-first order.- Parameters:
- stream- Binary output stream
- i- Long to be serialized
- Throws:
- IOException
 
- 
readVLongReads a zero-compressed encoded long from input stream and returns it.- Parameters:
- stream- Binary input stream
- Returns:
- deserialized long from stream.
- Throws:
- IOException
 
- 
readVIntReads a zero-compressed encoded integer from input stream and returns it.- Parameters:
- stream- Binary input stream
- Returns:
- deserialized integer from stream.
- Throws:
- IOException
 
- 
isNegativeVIntpublic static boolean isNegativeVInt(byte value) Given the first byte of a vint/vlong, determine the sign.- Parameters:
- value- the first byte
- Returns:
- is the value negative
 
- 
decodeVIntSizepublic static int decodeVIntSize(byte value) Parse the first byte of a vint/vlong to determine the number of bytes.- Parameters:
- value- the first byte of the vint/vlong
- Returns:
- the total number of bytes (1 to 9)
 
- 
getVIntSizepublic static int getVIntSize(long i) Get the encoded length if an integer is stored in a variable-length format.- Returns:
- the encoded length
 
- 
skipFullySkip len number of bytes in input streamin.- Parameters:
- in- input stream
- len- number of bytes to skip
- Throws:
- IOException- when skipped less number of bytes
 
 
-