Package org.apache.flink.core.memory
Class DataOutputSerializer
- java.lang.Object
-
- org.apache.flink.core.memory.DataOutputSerializer
-
- All Implemented Interfaces:
DataOutput,DataOutputView,MemorySegmentWritable
public class DataOutputSerializer extends Object implements DataOutputView, MemorySegmentWritable
A simple and efficient serializer for theDataOutputinterface.
-
-
Constructor Summary
Constructors Constructor Description DataOutputSerializer(int startSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()byte[]getByteArray()Deprecated.Replaced bygetSharedBuffer()for a better, safer name.byte[]getCopyOfBuffer()Gets a copy of the buffer that has the right length for the data serialized so far.byte[]getSharedBuffer()Gets a reference to the internal byte buffer.intlength()voidsetPosition(int position)voidsetPositionUnsafe(int position)voidskipBytesToWrite(int numBytes)SkipsnumBytesbytes memory.StringtoString()ByteBufferwrapAsByteBuffer()voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwrite(DataInputView source, int numBytes)CopiesnumBytesbytes from the source to this view.voidwrite(MemorySegment segment, int off, int len)Writeslenbytes from memory segmentsegmentstarting at offsetoff, in order, to the output.voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteBytes(String s)voidwriteChar(int v)voidwriteChars(String s)voidwriteDouble(double v)voidwriteFloat(float v)voidwriteInt(int v)voidwriteIntUnsafe(int v, int pos)voidwriteLong(long v)voidwriteShort(int v)voidwriteUTF(String str)
-
-
-
Method Detail
-
wrapAsByteBuffer
public ByteBuffer wrapAsByteBuffer()
-
getByteArray
@Deprecated public byte[] getByteArray()
Deprecated.Replaced bygetSharedBuffer()for a better, safer name.
-
getSharedBuffer
public byte[] getSharedBuffer()
Gets a reference to the internal byte buffer. This buffer may be larger than the actual serialized data. Only the bytes from zero tolength()are valid. The buffer will also be overwritten with the next write calls.This method is useful when trying to avid byte copies, but should be used carefully.
- Returns:
- A reference to the internal shared and reused buffer.
-
getCopyOfBuffer
public byte[] getCopyOfBuffer()
Gets a copy of the buffer that has the right length for the data serialized so far. The returned buffer is an exclusive copy and can be safely used without being overwritten by future write calls to this serializer.This method is equivalent to
Arrays.copyOf(getSharedBuffer(), length());- Returns:
- A non-shared copy of the serialization buffer.
-
clear
public void clear()
-
length
public int length()
-
write
public void write(int b) throws IOException- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
public void write(MemorySegment segment, int off, int len) throws IOException
Description copied from interface:MemorySegmentWritableWriteslenbytes from memory segmentsegmentstarting at offsetoff, in order, to the output.- Specified by:
writein interfaceMemorySegmentWritable- Parameters:
segment- memory segment to copy the bytes from.off- the start offset in the memory segment.len- The number of bytes to copy.- Throws:
IOException- if an I/O error occurs.
-
writeBoolean
public void writeBoolean(boolean v) throws IOException- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
public void writeByte(int v) throws IOException- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeBytes
public void writeBytes(String s) throws IOException
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChar
public void writeChar(int v) throws IOException- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeDouble
public void writeDouble(double v) throws IOException- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeFloat
public void writeFloat(float v) throws IOException- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeInt
public void writeInt(int v) throws IOException- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeIntUnsafe
public void writeIntUnsafe(int v, int pos) throws IOException- Throws:
IOException
-
writeLong
public void writeLong(long v) throws IOException- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeShort
public void writeShort(int v) throws IOException- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeUTF
public void writeUTF(String str) throws IOException
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
skipBytesToWrite
public void skipBytesToWrite(int numBytes) throws IOExceptionDescription copied from interface:DataOutputViewSkipsnumBytesbytes memory. If some program reads the memory that was skipped over, the results are undefined.- Specified by:
skipBytesToWritein interfaceDataOutputView- Parameters:
numBytes- The number of bytes to skip.- Throws:
IOException- Thrown, if any I/O related problem occurred such that the view could not be advanced to the desired position.
-
write
public void write(DataInputView source, int numBytes) throws IOException
Description copied from interface:DataOutputViewCopiesnumBytesbytes from the source to this view.- Specified by:
writein interfaceDataOutputView- Parameters:
source- The source to copy the bytes from.numBytes- The number of bytes to copy.- Throws:
IOException- Thrown, if any I/O related problem occurred, such that either the input view could not be read, or the output could not be written.
-
setPosition
public void setPosition(int position)
-
setPositionUnsafe
public void setPositionUnsafe(int position)
-
-