@Public
@Stable
public final class WritableUtils
extends java.lang.Object
| Constructor | Description |
|---|---|
WritableUtils() |
| Modifier and Type | Method | 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(java.io.DataInput in) |
|
static java.lang.String |
readCompressedString(java.io.DataInput in) |
|
static java.lang.String[] |
readCompressedStringArray(java.io.DataInput in) |
|
static <T extends java.lang.Enum<T>> |
readEnum(java.io.DataInput in,
java.lang.Class<T> enumType) |
Read an Enum value from DataInput, Enums are read and written
using String values.
|
static java.lang.String |
readString(java.io.DataInput in) |
|
static java.lang.String[] |
readStringArray(java.io.DataInput in) |
|
static java.lang.String |
readStringSafely(java.io.DataInput in,
int maxLength) |
Read a string, but check it for sanity.
|
static int |
readVInt(java.io.DataInput stream) |
Reads a zero-compressed encoded integer from input stream and returns it.
|
static int |
readVIntInRange(java.io.DataInput stream,
int lower,
int upper) |
Reads an integer from the input stream and returns it.
|
static long |
readVLong(java.io.DataInput stream) |
Reads a zero-compressed encoded long from input stream and returns it.
|
static void |
skipCompressedByteArray(java.io.DataInput in) |
|
static void |
skipFully(java.io.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(java.io.DataOutput out,
byte[] bytes) |
|
static int |
writeCompressedString(java.io.DataOutput out,
java.lang.String s) |
|
static void |
writeCompressedStringArray(java.io.DataOutput out,
java.lang.String[] s) |
|
static void |
writeEnum(java.io.DataOutput out,
java.lang.Enum<?> enumVal) |
writes String value of enum to DataOutput.
|
static void |
writeString(java.io.DataOutput out,
java.lang.String s) |
|
static void |
writeStringArray(java.io.DataOutput out,
java.lang.String[] s) |
|
static void |
writeVInt(java.io.DataOutput stream,
int i) |
Serializes an integer to a binary stream with zero-compressed encoding.
|
static void |
writeVLong(java.io.DataOutput stream,
long i) |
Serializes a long to a binary stream with zero-compressed encoding.
|
public static byte[] readCompressedByteArray(java.io.DataInput in)
throws java.io.IOException
java.io.IOExceptionpublic static void skipCompressedByteArray(java.io.DataInput in)
throws java.io.IOException
java.io.IOExceptionpublic static int writeCompressedByteArray(java.io.DataOutput out,
byte[] bytes)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String readCompressedString(java.io.DataInput in)
throws java.io.IOException
java.io.IOExceptionpublic static int writeCompressedString(java.io.DataOutput out,
java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic static void writeString(java.io.DataOutput out,
java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String readString(java.io.DataInput in)
throws java.io.IOException
java.io.IOExceptionpublic static void writeStringArray(java.io.DataOutput out,
java.lang.String[] s)
throws java.io.IOException
java.io.IOExceptionpublic static void writeCompressedStringArray(java.io.DataOutput out,
java.lang.String[] s)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String[] readStringArray(java.io.DataInput in)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String[] readCompressedStringArray(java.io.DataInput in)
throws java.io.IOException
java.io.IOExceptionpublic static void displayByteArray(byte[] record)
public static <T extends Writable> T clone(T orig, Configuration conf)
T - Generics Type T.orig - The object to copyconf - input Configuration.@Deprecated public static void cloneInto(Writable dst, Writable src) throws java.io.IOException
dst - the object to copy fromsrc - the object to copy into, which is destroyedjava.io.IOException - raised on errors performing I/O.public static void writeVInt(java.io.DataOutput stream,
int i)
throws java.io.IOException
stream - Binary output streami - Integer to be serializedjava.io.IOException - raised on errors performing I/O.public static void writeVLong(java.io.DataOutput stream,
long i)
throws java.io.IOException
stream - Binary output streami - Long to be serializedjava.io.IOException - raised on errors performing I/O.public static long readVLong(java.io.DataInput stream)
throws java.io.IOException
stream - Binary input streamjava.io.IOException - raised on errors performing I/O.public static int readVInt(java.io.DataInput stream)
throws java.io.IOException
stream - Binary input streamjava.io.IOException - raised on errors performing I/O.public static int readVIntInRange(java.io.DataInput stream,
int lower,
int upper)
throws java.io.IOException
stream - Binary input streamlower - input lower.upper - input upper.java.io.IOException - raised on errors performing I/O.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)
i - input i.public static <T extends java.lang.Enum<T>> T readEnum(java.io.DataInput in,
java.lang.Class<T> enumType)
throws java.io.IOException
T - Enum typein - DataInput to read fromenumType - Class type of Enumjava.io.IOException - raised on errors performing I/O.public static void writeEnum(java.io.DataOutput out,
java.lang.Enum<?> enumVal)
throws java.io.IOException
out - Dataoutput streamenumVal - enum valuejava.io.IOException - raised on errors performing I/O.public static void skipFully(java.io.DataInput in,
int len)
throws java.io.IOException
in - input streamlen - number of bytes to skipjava.io.IOException - when skipped less number of bytespublic static byte[] toByteArray(Writable... writables)
writables - input writables.public static java.lang.String readStringSafely(java.io.DataInput in,
int maxLength)
throws java.io.IOException,
java.lang.IllegalArgumentException
in - the stream to read frommaxLength - the largest acceptable length of the encoded stringjava.io.IOException - if reading from the DataInput failsjava.lang.IllegalArgumentException - if the encoded byte size for string
is negative or larger than maxSize. Only the vint is read.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.