@InterfaceAudience.Public @InterfaceStability.Stable public final class WritableUtils extends Object
Constructor and Description |
---|
WritableUtils() |
Modifier and Type | Method and Description |
---|---|
static <T extends Writable> |
clone(T orig,
Configuration conf)
Make a copy of a writable object using serialization to a buffer.
|
static void |
cloneInto(Writable dst,
Writable src)
Deprecated.
use ReflectionUtils.cloneInto instead.
|
static int |
decodeVIntSize(byte value)
Parse the first byte of a vint/vlong to determine the number of bytes
|
static void |
displayByteArray(byte[] record) |
static int |
getVIntSize(long i)
Get the encoded length if an integer is stored in a variable-length format
|
static boolean |
isNegativeVInt(byte value)
Given the first byte of a vint/vlong, determine the sign
|
static byte[] |
readCompressedByteArray(DataInput in) |
static String |
readCompressedString(DataInput in) |
static String[] |
readCompressedStringArray(DataInput in) |
static <T extends Enum<T>> |
readEnum(DataInput in,
Class<T> enumType)
Read an Enum value from DataInput, Enums are read and written
using String values.
|
static String |
readString(DataInput in) |
static String[] |
readStringArray(DataInput in) |
static String |
readStringSafely(DataInput in,
int maxLength)
Read a string, but check it for sanity.
|
static int |
readVInt(DataInput stream)
Reads a zero-compressed encoded integer from input stream and returns it.
|
static int |
readVIntInRange(DataInput stream,
int lower,
int upper)
Reads an integer from the input stream and returns it.
|
static long |
readVLong(DataInput stream)
Reads a zero-compressed encoded long from input stream and returns it.
|
static void |
skipCompressedByteArray(DataInput in) |
static void |
skipFully(DataInput in,
int len)
Skip len number of bytes in input streamin
|
static byte[] |
toByteArray(Writable... writables)
Convert writables to a byte array
|
static int |
writeCompressedByteArray(DataOutput out,
byte[] bytes) |
static int |
writeCompressedString(DataOutput out,
String s) |
static void |
writeCompressedStringArray(DataOutput out,
String[] s) |
static void |
writeEnum(DataOutput out,
Enum<?> enumVal)
writes String value of enum to DataOutput.
|
static void |
writeString(DataOutput out,
String s) |
static void |
writeStringArray(DataOutput out,
String[] s) |
static void |
writeVInt(DataOutput stream,
int i)
Serializes an integer to a binary stream with zero-compressed encoding.
|
static void |
writeVLong(DataOutput stream,
long i)
Serializes a long to a binary stream with zero-compressed encoding.
|
public WritableUtils()
public static byte[] readCompressedByteArray(DataInput in) throws IOException
IOException
public static void skipCompressedByteArray(DataInput in) throws IOException
IOException
public static int writeCompressedByteArray(DataOutput out, byte[] bytes) throws IOException
IOException
public static String readCompressedString(DataInput in) throws IOException
IOException
public static int writeCompressedString(DataOutput out, String s) throws IOException
IOException
public static void writeString(DataOutput out, String s) throws IOException
IOException
public static String readString(DataInput in) throws IOException
IOException
public static void writeStringArray(DataOutput out, String[] s) throws IOException
IOException
public static void writeCompressedStringArray(DataOutput out, String[] s) throws IOException
IOException
public static String[] readStringArray(DataInput in) throws IOException
IOException
public static String[] readCompressedStringArray(DataInput in) throws IOException
IOException
public static void displayByteArray(byte[] record)
public static <T extends Writable> T clone(T orig, Configuration conf)
orig
- The object to copy@Deprecated public static void cloneInto(Writable dst, Writable src) throws IOException
dst
- the object to copy fromsrc
- the object to copy into, which is destroyedIOException
public static void writeVInt(DataOutput stream, int i) throws IOException
stream
- Binary output streami
- Integer to be serializedIOException
public static void writeVLong(DataOutput stream, long i) throws IOException
stream
- Binary output streami
- Long to be serializedIOException
public static long readVLong(DataInput stream) throws IOException
stream
- Binary input streamIOException
public static int readVInt(DataInput stream) throws IOException
stream
- Binary input streamIOException
public static int readVIntInRange(DataInput stream, int lower, int upper) throws IOException
stream
- Binary input streamIOException
public static boolean isNegativeVInt(byte value)
value
- the first bytepublic static int decodeVIntSize(byte value)
value
- the first byte of the vint/vlongpublic static int getVIntSize(long i)
public static <T extends Enum<T>> T readEnum(DataInput in, Class<T> enumType) throws IOException
T
- Enum typein
- DataInput to read fromenumType
- Class type of EnumIOException
public static void writeEnum(DataOutput out, Enum<?> enumVal) throws IOException
out
- Dataoutput streamenumVal
- enum valueIOException
public static void skipFully(DataInput in, int len) throws IOException
in
- input streamlen
- number of bytes to skipIOException
- when skipped less number of bytespublic static byte[] toByteArray(Writable... writables)
public static String readStringSafely(DataInput in, int maxLength) throws IOException, IllegalArgumentException
in
- the stream to read frommaxLength
- the largest acceptable length of the encoded stringIOException
- if reading from the DataInput failsIllegalArgumentException
- if the encoded byte size for string
is negative or larger than maxSize. Only the vint is read.Copyright © 2017 Apache Software Foundation. All rights reserved.