Package org.datavec.api.writable
Class WritableFactory
- java.lang.Object
-
- org.datavec.api.writable.WritableFactory
-
public class WritableFactory extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static WritableFactory
getInstance()
Writable
newWritable(short writableTypeKey)
Create a new writable instance (using reflection) given the specified keyWritable
readWithType(DataInput dataInput)
Read a Writable From the DataInput, where the Writable was previously written usingwriteWithType(Writable, DataOutput)
void
registerWritableType(short writableTypeKey, @NonNull Class<? extends Writable> writableClass)
Register a writable class with a specific key (as a short).void
writeWithType(Writable w, DataOutput dataOutput)
A convenience method for writing a given Writable object to a DataOutput.
-
-
-
Method Detail
-
getInstance
public static WritableFactory getInstance()
- Returns:
- Singleton WritableFactory instance
-
registerWritableType
public void registerWritableType(short writableTypeKey, @NonNull @NonNull Class<? extends Writable> writableClass)
Register a writable class with a specific key (as a short). Note that key values must be unique for each type of Writable, as they are used as type information in certain types of serialisation. Consequently, an exception will be thrown If the key value is not unique or is already assigned.
Note that in general, this method needs to only be used for custom Writable types; Care should be taken to ensure that the given key does not change once assigned.- Parameters:
writableTypeKey
- Key for the WritablewritableClass
- Class for the given key. Must have a no-arg constructor
-
newWritable
public Writable newWritable(short writableTypeKey)
Create a new writable instance (using reflection) given the specified key- Parameters:
writableTypeKey
- Key to create a new writable instance for- Returns:
- A new (empty/default) Writable instance
-
writeWithType
public void writeWithType(Writable w, DataOutput dataOutput) throws IOException
A convenience method for writing a given Writable object to a DataOutput. The key is 1st written (a single short) followed by the value from writable.- Parameters:
w
- Writable valuedataOutput
- DataOutput to write both key and value to- Throws:
IOException
- If an error occurs during writing to the DataOutput
-
readWithType
public Writable readWithType(DataInput dataInput) throws IOException
Read a Writable From the DataInput, where the Writable was previously written usingwriteWithType(Writable, DataOutput)
- Parameters:
dataInput
- DataInput to read the Writable from- Returns:
- Writable from the DataInput
- Throws:
IOException
- In an error occurs during reading
-
-