public class WritableUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends org.apache.hadoop.io.Writable> |
copyInto(T from,
T to)
Copy
from into to , by serializing and deserializing it. |
static <T extends org.apache.hadoop.io.Writable> |
copyInto(T from,
T to,
boolean checkOverRead)
Copy
from into to , by serializing and deserializing it. |
static <T extends org.apache.hadoop.io.Writable> |
createCopy(T original)
Create a copy of Writable object, by serializing and deserializing it.
|
static <T extends org.apache.hadoop.io.Writable> |
createCopy(T original,
Class<? extends T> outputClass,
ImmutableClassesGiraphConfiguration conf)
Create a copy of Writable object, by serializing and deserializing it.
|
static <T extends org.apache.hadoop.io.Writable> |
createCopy(T original,
ValueFactory<T> classFactory,
ImmutableClassesGiraphConfiguration conf)
Create a copy of Writable object, by serializing and deserializing it.
|
static <T extends org.apache.hadoop.io.Writable> |
createCopy(UnsafeByteArrayOutputStream reusableOut,
UnsafeReusableByteArrayInput reusableIn,
T original,
ImmutableClassesGiraphConfiguration conf)
Create a copy of Writable object, by serializing and deserializing it.
|
static <W extends org.apache.hadoop.io.Writable> |
createWritable(Class<W> klass)
Instantiate a new Writable, checking for NullWritable along the way.
|
static <W extends org.apache.hadoop.io.Writable> |
createWritable(Class<W> klass,
ImmutableClassesGiraphConfiguration configuration)
Instantiate a new Writable, checking for NullWritable along the way.
|
static <T extends org.apache.hadoop.io.Writable> |
fromByteArray(byte[] data,
T to)
Deserialize from given byte array into given writable,
using new instance of ExtendedByteArrayDataInput.
|
static <T extends org.apache.hadoop.io.Writable> |
fromByteArrayUnsafe(byte[] data,
T to,
UnsafeReusableByteArrayInput reusableInput)
Deserialize from given byte array into given writable,
using given reusable UnsafeReusableByteArrayInput.
|
static <T> Class<T> |
readClass(DataInput input)
Read class from data input.
|
static <I extends org.apache.hadoop.io.WritableComparable,E extends org.apache.hadoop.io.Writable> |
readEdge(DataInput in,
Edge<I,E> edge)
Read an edge from an input stream.
|
static <T extends Enum<T>> |
readEnum(DataInput input)
Reads enum from the stream, serialized by writeEnum
|
static ExtendedDataOutput |
readExtendedDataOutput(DataInput in,
ImmutableClassesGiraphConfiguration conf)
Read ExtendedDataOutput from DataInput
|
static void |
readFieldsFromByteArray(byte[] byteArray,
org.apache.hadoop.io.Writable... writableObjects)
Read fields from byteArray to a Writeable object.
|
static void |
readFieldsFromByteArrayWithSize(byte[] byteArray,
org.apache.hadoop.io.Writable writableObject,
boolean unsafe)
Read fields from byteArray to a Writeable object, skipping the size.
|
static void |
readFieldsFromZnode(ZooKeeperExt zkExt,
String zkPath,
boolean watch,
org.apache.zookeeper.data.Stat stat,
org.apache.hadoop.io.Writable... writableObjects)
Read fields from a ZooKeeper znode.
|
static <T extends org.apache.hadoop.io.Writable> |
readIfNotNullAndObject(T reusableObject,
Class<T> objectClass,
DataInput in)
First read a boolean saying whether an object is not null,
and if it's not read the object
|
static int[] |
readIntArray(DataInput dataInput)
Reads primitive int array from input stream.
|
static List<? extends org.apache.hadoop.io.Writable> |
readList(DataInput input)
Reads list of Writable objects from data input stream.
|
static <T extends org.apache.hadoop.io.Writable> |
readListFieldsFromByteArray(byte[] byteArray,
Class<? extends T> writableClass,
org.apache.hadoop.conf.Configuration conf)
Read fields from byteArray to a list of objects.
|
static <T extends org.apache.hadoop.io.Writable> |
readListFieldsFromZnode(ZooKeeperExt zkExt,
String zkPath,
boolean watch,
org.apache.zookeeper.data.Stat stat,
Class<? extends T> writableClass,
org.apache.hadoop.conf.Configuration conf)
Read fields from a ZooKeeper znode into a list of objects.
|
static long[] |
readLongArray(DataInput dataInput)
Reads primitive long array from input stream.
|
static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> |
readVertexFromDataInput(DataInput input,
ImmutableClassesGiraphConfiguration<I,V,E> conf)
Reads data from input stream to initialize Vertex.
|
static <T extends org.apache.hadoop.io.Writable> |
readWritableObject(DataInput input,
ImmutableClassesGiraphConfiguration conf)
Reads object from input stream
|
static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> |
reinitializeVertexFromByteArray(byte[] byteArray,
Vertex<I,V,E> vertex,
boolean unsafe,
ImmutableClassesGiraphConfiguration<I,V,E> conf)
Read vertex data from byteArray to a Writeable object, skipping the size.
|
static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> |
reinitializeVertexFromDataInput(DataInput input,
Vertex<I,V,E> vertex,
ImmutableClassesGiraphConfiguration<I,V,E> conf)
Reads data from input stream to initialize Vertex.
|
static int |
size(org.apache.hadoop.io.Writable w)
Serialize given writable object, and return it's size.
|
static <T extends org.apache.hadoop.io.Writable> |
toByteArray(T w)
Serialize given writable to byte array,
using new instance of ExtendedByteArrayDataOutput.
|
static <T extends org.apache.hadoop.io.Writable> |
toByteArrayUnsafe(T w)
Serialize given writable to byte array,
using new instance of UnsafeByteArrayOutputStream.
|
static <T> void |
writeClass(Class<T> clazz,
DataOutput output)
Write class to data output.
|
static <I extends org.apache.hadoop.io.WritableComparable,E extends org.apache.hadoop.io.Writable> |
writeEdge(DataOutput out,
Edge<I,E> edge)
Write an edge to an output stream.
|
static <T extends Enum<T>> |
writeEnum(T enumValue,
DataOutput output)
Writes enum into a stream, by serializing class name and it's index
|
static void |
writeExtendedDataOutput(ExtendedDataOutput extendedDataOutput,
DataOutput out)
Write ExtendedDataOutput to DataOutput
|
static <T extends org.apache.hadoop.io.Writable> |
writeIfNotNullAndObject(T object,
DataOutput out)
First write a boolean saying whether an object is not null,
and if it's not write the object
|
static void |
writeIntArray(int[] array,
DataOutput dataOutput)
Writes primitive int array of ints into output stream.
|
static void |
writeList(List<? extends org.apache.hadoop.io.Writable> list,
DataOutput output)
Writes a list of Writable objects into output stream.
|
static byte[] |
writeListToByteArray(List<? extends org.apache.hadoop.io.Writable> writableList)
Write list of object to a byte array.
|
static ZooKeeperExt.PathStat |
writeListToZnode(ZooKeeperExt zkExt,
String zkPath,
int version,
List<? extends org.apache.hadoop.io.Writable> writableList)
Write list of objects to a ZooKeeper znode.
|
static void |
writeLongArray(DataOutput dataOutput,
long[] array)
Writes primitive long array of ints into output stream.
|
static byte[] |
writeToByteArray(org.apache.hadoop.io.Writable... writableObjects)
Write object to a byte array.
|
static byte[] |
writeToByteArrayWithSize(org.apache.hadoop.io.Writable writableObject,
boolean unsafe)
Write object to a byte array with the first 4 bytes as the size of the
entire buffer (including the size).
|
static byte[] |
writeToByteArrayWithSize(org.apache.hadoop.io.Writable writableObject,
byte[] buffer,
boolean unsafe)
Write object to a byte array with the first 4 bytes as the size of the
entire buffer (including the size).
|
static ZooKeeperExt.PathStat |
writeToZnode(ZooKeeperExt zkExt,
String zkPath,
int version,
org.apache.hadoop.io.Writable... writableObjects)
Write object to a ZooKeeper znode.
|
static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> |
writeVertexToByteArray(Vertex<I,V,E> vertex,
boolean unsafe,
ImmutableClassesGiraphConfiguration<I,V,E> conf)
Write vertex data to byte array with the first 4 bytes as the size of the
entire buffer (including the size).
|
static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> |
writeVertexToByteArray(Vertex<I,V,E> vertex,
byte[] buffer,
boolean unsafe,
ImmutableClassesGiraphConfiguration<I,V,E> conf)
Write vertex data to byte array with the first 4 bytes as the size of the
entire buffer (including the size).
|
static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> |
writeVertexToDataOutput(DataOutput output,
Vertex<I,V,E> vertex,
ImmutableClassesGiraphConfiguration<I,V,E> conf)
Writes Vertex data to output stream.
|
static void |
writeWritableObject(org.apache.hadoop.io.Writable object,
DataOutput output)
Write object to output stream
|
public static <W extends org.apache.hadoop.io.Writable> W createWritable(Class<W> klass)
W
- typeklass
- Classpublic static <W extends org.apache.hadoop.io.Writable> W createWritable(Class<W> klass, ImmutableClassesGiraphConfiguration configuration)
W
- typeklass
- Classconfiguration
- Configurationpublic static void readFieldsFromByteArray(byte[] byteArray, org.apache.hadoop.io.Writable... writableObjects)
byteArray
- Byte array to find the fields in.writableObjects
- Objects to fill in the fields.public static void readFieldsFromZnode(ZooKeeperExt zkExt, String zkPath, boolean watch, org.apache.zookeeper.data.Stat stat, org.apache.hadoop.io.Writable... writableObjects)
zkExt
- ZooKeeper instance.zkPath
- Path of znode.watch
- Add a watch?stat
- Stat of znode if desired.writableObjects
- Objects to read into.public static byte[] writeToByteArray(org.apache.hadoop.io.Writable... writableObjects)
writableObjects
- Objects to write from.public static void readFieldsFromByteArrayWithSize(byte[] byteArray, org.apache.hadoop.io.Writable writableObject, boolean unsafe)
byteArray
- Byte array to find the fields in.writableObject
- Object to fill in the fields.unsafe
- Use unsafe deserializationpublic static byte[] writeToByteArrayWithSize(org.apache.hadoop.io.Writable writableObject, boolean unsafe)
writableObject
- Object to write from.unsafe
- Use unsafe serialization?public static byte[] writeToByteArrayWithSize(org.apache.hadoop.io.Writable writableObject, byte[] buffer, boolean unsafe)
writableObject
- Object to write from.buffer
- Use this buffer insteadunsafe
- Use unsafe serialization?public static ZooKeeperExt.PathStat writeToZnode(ZooKeeperExt zkExt, String zkPath, int version, org.apache.hadoop.io.Writable... writableObjects)
zkExt
- ZooKeeper instance.zkPath
- Path of znode.version
- Version of the write.writableObjects
- Objects to write from.public static byte[] writeListToByteArray(List<? extends org.apache.hadoop.io.Writable> writableList)
writableList
- List of object to write from.public static ZooKeeperExt.PathStat writeListToZnode(ZooKeeperExt zkExt, String zkPath, int version, List<? extends org.apache.hadoop.io.Writable> writableList)
zkExt
- ZooKeeper instance.zkPath
- Path of znode.version
- Version of the write.writableList
- List of objects to write from.public static <T extends org.apache.hadoop.io.Writable> List<T> readListFieldsFromByteArray(byte[] byteArray, Class<? extends T> writableClass, org.apache.hadoop.conf.Configuration conf)
T
- Object typebyteArray
- Byte array to find the fields in.writableClass
- Class of the objects to instantiate.conf
- Configuration used for instantiation (i.e Configurable)public static <T extends org.apache.hadoop.io.Writable> List<T> readListFieldsFromZnode(ZooKeeperExt zkExt, String zkPath, boolean watch, org.apache.zookeeper.data.Stat stat, Class<? extends T> writableClass, org.apache.hadoop.conf.Configuration conf)
T
- Object typezkExt
- ZooKeeper instance.zkPath
- Path of znode.watch
- Add a watch?stat
- Stat of znode if desired.writableClass
- Class of the objects to instantiate.conf
- Configuration used for instantiation (i.e Configurable)public static void writeExtendedDataOutput(ExtendedDataOutput extendedDataOutput, DataOutput out) throws IOException
extendedDataOutput
- ExtendedDataOutput to writeout
- DataOutput to write toIOException
public static ExtendedDataOutput readExtendedDataOutput(DataInput in, ImmutableClassesGiraphConfiguration conf) throws IOException
in
- DataInput to read fromconf
- ConfigurationIOException
public static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> byte[] writeVertexToByteArray(Vertex<I,V,E> vertex, byte[] buffer, boolean unsafe, ImmutableClassesGiraphConfiguration<I,V,E> conf)
I
- Vertex idV
- Vertex valueE
- Edge valuevertex
- Vertex to write from.buffer
- Use this buffer insteadunsafe
- Use unsafe serialization?conf
- Configurationpublic static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> byte[] writeVertexToByteArray(Vertex<I,V,E> vertex, boolean unsafe, ImmutableClassesGiraphConfiguration<I,V,E> conf)
I
- Vertex idV
- Vertex valueE
- Edge valuevertex
- Vertex to write from.unsafe
- Use unsafe serialization?conf
- Configurationpublic static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> void reinitializeVertexFromByteArray(byte[] byteArray, Vertex<I,V,E> vertex, boolean unsafe, ImmutableClassesGiraphConfiguration<I,V,E> conf)
I
- Vertex idV
- Vertex valueE
- Edge valuebyteArray
- Byte array to find the fields in.vertex
- Vertex to fill in the fields.unsafe
- Use unsafe deserializationconf
- Configurationpublic static <I extends org.apache.hadoop.io.WritableComparable,E extends org.apache.hadoop.io.Writable> void writeEdge(DataOutput out, Edge<I,E> edge) throws IOException
I
- Vertex idE
- Edge valueout
- Data outputedge
- Edge to writeIOException
public static <I extends org.apache.hadoop.io.WritableComparable,E extends org.apache.hadoop.io.Writable> void readEdge(DataInput in, Edge<I,E> edge) throws IOException
I
- Vertex idE
- Edge valuein
- Data inputedge
- Edge to fill in-placeIOException
public static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> void reinitializeVertexFromDataInput(DataInput input, Vertex<I,V,E> vertex, ImmutableClassesGiraphConfiguration<I,V,E> conf) throws IOException
I
- Vertex idV
- Vertex valueE
- Edge valueinput
- The input streamvertex
- The vertex to initializeconf
- ConfigurationIOException
public static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> Vertex<I,V,E> readVertexFromDataInput(DataInput input, ImmutableClassesGiraphConfiguration<I,V,E> conf) throws IOException
I
- Vertex idV
- Vertex valueE
- Edge valueinput
- The input streamconf
- ConfigurationIOException
public static <I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable> void writeVertexToDataOutput(DataOutput output, Vertex<I,V,E> vertex, ImmutableClassesGiraphConfiguration<I,V,E> conf) throws IOException
I
- Vertex idV
- Vertex valueE
- Edge valueoutput
- the output streamvertex
- The vertex to serializeconf
- ConfigurationIOException
public static <T> void writeClass(Class<T> clazz, DataOutput output) throws IOException
T
- Class typeclazz
- Classoutput
- Data outputIOException
public static <T> Class<T> readClass(DataInput input) throws IOException
writeClass(Class, DataOutput)
.T
- Class typeinput
- Data inputIOException
public static void writeWritableObject(org.apache.hadoop.io.Writable object, DataOutput output) throws IOException
object
- Objectoutput
- Output streamIOException
public static <T extends org.apache.hadoop.io.Writable> T readWritableObject(DataInput input, ImmutableClassesGiraphConfiguration conf) throws IOException
T
- Object typeinput
- Input streamconf
- ConfigurationIOException
public static void writeList(List<? extends org.apache.hadoop.io.Writable> list, DataOutput output) throws IOException
list
- serialized objectoutput
- the output streamIOException
public static List<? extends org.apache.hadoop.io.Writable> readList(DataInput input) throws IOException
input
- input streamIOException
public static void writeIntArray(int[] array, DataOutput dataOutput) throws IOException
array
- array to be writtendataOutput
- output streamIOException
public static int[] readIntArray(DataInput dataInput) throws IOException
dataInput
- input stream to read fromIOException
public static void writeLongArray(DataOutput dataOutput, long[] array) throws IOException
array
- array to be writtendataOutput
- output streamIOException
public static long[] readLongArray(DataInput dataInput) throws IOException
dataInput
- input stream to read fromIOException
public static <T extends Enum<T>> void writeEnum(T enumValue, DataOutput output) throws IOException
T
- Enum typeenumValue
- Enum valueoutput
- Output streamIOException
public static <T extends Enum<T>> T readEnum(DataInput input) throws IOException
T
- Enum typeinput
- Input streamIOException
public static <T extends org.apache.hadoop.io.Writable> void copyInto(T from, T to)
from
into to
, by serializing and deserializing it.
Since it is creating streams inside, it's mostly useful for
tests/non-performant code.T
- Type of the objectfrom
- Object to copy fromto
- Object to copy intopublic static <T extends org.apache.hadoop.io.Writable> void copyInto(T from, T to, boolean checkOverRead)
from
into to
, by serializing and deserializing it.
Since it is creating streams inside, it's mostly useful for
tests/non-performant code.T
- Type of the objectfrom
- Object to copy fromto
- Object to copy intocheckOverRead
- if true, will add one more byte at the end of writing,
to make sure read is not touching it. Useful for testspublic static <T extends org.apache.hadoop.io.Writable> T createCopy(UnsafeByteArrayOutputStream reusableOut, UnsafeReusableByteArrayInput reusableIn, T original, ImmutableClassesGiraphConfiguration conf)
T
- Type of the objectreusableOut
- Reusable output stream to serialize intoreusableIn
- Reusable input stream to deserialize out oforiginal
- Original value of which to make a copyconf
- Configurationpublic static final <T extends org.apache.hadoop.io.Writable> T createCopy(T original)
T
- Type of the objectoriginal
- Original value of which to make a copypublic static final <T extends org.apache.hadoop.io.Writable> T createCopy(T original, Class<? extends T> outputClass, ImmutableClassesGiraphConfiguration conf)
T
- Type of the objectoriginal
- Original value of which to make a copyoutputClass
- Expected copy class, needs to match originalconf
- Configurationpublic static final <T extends org.apache.hadoop.io.Writable> T createCopy(T original, ValueFactory<T> classFactory, ImmutableClassesGiraphConfiguration conf)
T
- Type of the objectoriginal
- Original value of which to make a copyclassFactory
- Factory to create new empty object fromconf
- Configurationpublic static int size(org.apache.hadoop.io.Writable w)
w
- Writable objectpublic static <T extends org.apache.hadoop.io.Writable> byte[] toByteArray(T w)
T
- Type of the objectw
- Writable objectpublic static <T extends org.apache.hadoop.io.Writable> void fromByteArray(byte[] data, T to)
T
- Type of the objectdata
- Byte array representing writableto
- Object to fillpublic static <T extends org.apache.hadoop.io.Writable> byte[] toByteArrayUnsafe(T w)
T
- Type of the objectw
- Writable objectpublic static <T extends org.apache.hadoop.io.Writable> void fromByteArrayUnsafe(byte[] data, T to, UnsafeReusableByteArrayInput reusableInput)
T
- Type of the objectdata
- Byte array representing writableto
- Object to fillreusableInput
- Reusable input to usepublic static <T extends org.apache.hadoop.io.Writable> void writeIfNotNullAndObject(T object, DataOutput out) throws IOException
T
- Object typeobject
- Object to writeout
- DataOutput to write toIOException
public static <T extends org.apache.hadoop.io.Writable> T readIfNotNullAndObject(T reusableObject, Class<T> objectClass, DataInput in) throws IOException
T
- Object typereusableObject
- Reuse this object instanceobjectClass
- Class of the object, to create if reusableObject is nullin
- DataInput to read fromIOException
Copyright © 2011-2020 The Apache Software Foundation. All Rights Reserved.