Package org.datavec.api.writable
Class BytesWritable
- java.lang.Object
-
- org.datavec.api.writable.ArrayWritable
-
- org.datavec.api.writable.BytesWritable
-
- All Implemented Interfaces:
Serializable
,Writable
public class BytesWritable extends ArrayWritable
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BytesWritable(byte[] content)
Pass in the content for this writable
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataBuffer
asNd4jBuffer(DataType type, int elementSize)
Convert the underlying contents of thisWritable
to an nd4jDataBuffer
.boolean
equals(Object o)
double
getDouble(long i)
float
getFloat(long i)
int
getInt(long i)
long
getLong(long i)
WritableType
getType()
Get the type of the writable.int
hashCode()
long
length()
void
readFields(DataInput in)
Deserialize the fields of this object fromin
.void
write(DataOutput out)
Serialize the fields of this object toout
.void
writeType(DataOutput out)
Write the type (a single short value) to the DataOutput.-
Methods inherited from class org.datavec.api.writable.ArrayWritable
toDouble, toFloat, toInt, toLong
-
-
-
-
Method Detail
-
asNd4jBuffer
public DataBuffer asNd4jBuffer(DataType type, int elementSize)
Convert the underlying contents of thisWritable
to an nd4jDataBuffer
. Note that this is a *copy* of the underlying buffer. Also note thatByteBuffer.allocateDirect(int)
is used for allocation. This should be considered an expensive operation. This buffer should be cached when used. Once used, this can be used in standard Nd4j operations. Beyond that, the reason we have to use allocateDirect is due to nd4j data buffers being stored off heap (whether on cpu or gpu)- Parameters:
type
- the type of the data bufferelementSize
- the size of each element in the buffer- Returns:
- the equivalent nd4j data buffer
-
length
public long length()
- Specified by:
length
in classArrayWritable
-
getDouble
public double getDouble(long i)
- Specified by:
getDouble
in classArrayWritable
-
getFloat
public float getFloat(long i)
- Specified by:
getFloat
in classArrayWritable
-
getInt
public int getInt(long i)
- Specified by:
getInt
in classArrayWritable
-
getLong
public long getLong(long i)
- Specified by:
getLong
in classArrayWritable
-
write
public void write(DataOutput out) throws IOException
Description copied from interface:Writable
Serialize the fields of this object toout
.- Parameters:
out
-DataOuput
to serialize this object into.- Throws:
IOException
-
readFields
public void readFields(DataInput in) throws IOException
Description copied from interface:Writable
Deserialize the fields of this object fromin
.For efficiency, implementations should attempt to re-use storage in the existing object where possible.
- Parameters:
in
-DataInput
to deseriablize this object from.- Throws:
IOException
-
writeType
public void writeType(DataOutput out) throws IOException
Description copied from interface:Writable
Write the type (a single short value) to the DataOutput. SeeWritableFactory
for details.- Parameters:
out
- DataOutput to write to- Throws:
IOException
- For errors during writing
-
getType
public WritableType getType()
Description copied from interface:Writable
Get the type of the writable.- Returns:
-
-