Class DirectByteBufferOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.nemo.runtime.executor.data.DirectByteBufferOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public final class DirectByteBufferOutputStream extends java.io.OutputStream
This class is a customized output stream implementation backed byByteBuffer
, which utilizes off heap memory when writing the data via MemoryPoolAssigner. Deletion ofdataList
, which is the memory this outputstream holds, occurs when the corresponding block is deleted.
-
-
Constructor Summary
Constructors Constructor Description DirectByteBufferOutputStream(MemoryPoolAssigner memoryPoolAssigner)
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closing this output stream has no effect.java.util.List<MemoryChunk>
getMemoryChunkList()
Returns the list ofMemoryChunk
s that contains the written data.int
size()
Returns the size of the data written in this output stream.void
write(byte[] b)
Writesb.length
bytes from the specified byte array to this output stream.void
write(byte[] b, int off, int len)
Writeslen
bytes from the specified byte array starting at offsetoff
to this output stream.void
write(int b)
Writes the specified byte to this output stream.
-
-
-
Constructor Detail
-
DirectByteBufferOutputStream
public DirectByteBufferOutputStream(MemoryPoolAssigner memoryPoolAssigner) throws MemoryAllocationException
Default constructor.- Parameters:
memoryPoolAssigner
- for memory allocation.- Throws:
MemoryAllocationException
- if fails to allocate new memory.
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
Writes the specified byte to this output stream.- Specified by:
write
in classjava.io.OutputStream
- Parameters:
b
- the byte to be written.- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
Writesb.length
bytes from the specified byte array to this output stream.- Overrides:
write
in classjava.io.OutputStream
- Parameters:
b
- the byte to be written.- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
Writeslen
bytes from the specified byte array starting at offsetoff
to this output stream.- Overrides:
write
in classjava.io.OutputStream
- Parameters:
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.- Throws:
java.io.IOException
-
getMemoryChunkList
public java.util.List<MemoryChunk> getMemoryChunkList()
Returns the list ofMemoryChunk
s that contains the written data. List of flipped and duplicatedMemoryChunk
s are returned, which has independent position and limit, to reduce erroneous data read/write. This function has to be called when intended to read from the start of the list ofMemoryChunk
s, not for additional write.- Returns:
- the
LinkedList
ofMemoryChunk
s.
-
size
public int size()
Returns the size of the data written in this output stream.- Returns:
- the size of the data
-
close
public void close()
Closing this output stream has no effect.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
-
-