public class

NativePooledByteBufferOutputStream

extends PooledByteBufferOutputStream
java.lang.Object
   ↳ java.io.OutputStream
     ↳ com.facebook.common.memory.PooledByteBufferOutputStream
       ↳ com.facebook.imagepipeline.memory.NativePooledByteBufferOutputStream

Class Overview

An implementation of PooledByteBufferOutputStream that produces a NativePooledByteBuffer

Summary

Nested Classes
class NativePooledByteBufferOutputStream.InvalidStreamException An exception indicating that this stream is no longer valid  
Public Constructors
NativePooledByteBufferOutputStream(NativeMemoryChunkPool pool)
Construct a new instance of this outputstream
NativePooledByteBufferOutputStream(NativeMemoryChunkPool pool, int initialCapacity)
Construct a new instance of this output stream with this initial capacity It is not an error to have this initial capacity be inaccurate.
Public Methods
void close()
Closes the stream.
int size()
Returns the total number of bytes written to this stream so far.
NativePooledByteBuffer toByteBuffer()
Gets a PooledByteBuffer from the current contents.
void write(byte[] buffer, int offset, int count)
Writes count bytes from the byte array buffer starting at position offset to this stream.
void write(int oneByte)
Write one byte to the underlying stream.
[Expand]
Inherited Methods
From class com.facebook.common.memory.PooledByteBufferOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public Constructors

public NativePooledByteBufferOutputStream (NativeMemoryChunkPool pool)

Construct a new instance of this outputstream

Parameters
pool the pool to use

public NativePooledByteBufferOutputStream (NativeMemoryChunkPool pool, int initialCapacity)

Construct a new instance of this output stream with this initial capacity It is not an error to have this initial capacity be inaccurate. If the actual contents end up being larger than the initialCapacity, then we will reallocate memory if needed. If the actual contents are smaller, then we'll end up wasting some memory

Parameters
pool the pool to use
initialCapacity initial capacity to allocate for this stream

Public Methods

public void close ()

Closes the stream. Owned resources are released back to the pool. It is not allowed to call toByteBuffer after call to this method.

Throws
IOException

public int size ()

Returns the total number of bytes written to this stream so far.

Returns
  • the number of bytes written to this stream.

public NativePooledByteBuffer toByteBuffer ()

Gets a PooledByteBuffer from the current contents. If the stream has already been closed, then an InvalidStreamException is thrown.

Returns
  • a PooledByteBuffer instance for the contents of the stream

public void write (byte[] buffer, int offset, int count)

Writes count bytes from the byte array buffer starting at position offset to this stream. The underlying stream MUST be valid

Parameters
buffer the source buffer to read from
offset the start position in buffer from where to get bytes.
count the number of bytes from buffer to write to this stream.
Throws
IOException if an error occurs while writing to this stream.
IndexOutOfBoundsException if offset < 0 or count < 0, or if offset + count is bigger than the length of buffer.
NativePooledByteBufferOutputStream.InvalidStreamException if the stream is invalid

public void write (int oneByte)

Write one byte to the underlying stream. The underlying stream MUST be valid

Parameters
oneByte the one byte to write
Throws
NativePooledByteBufferOutputStream.InvalidStreamException if the stream is invalid
IOException in case of an I/O error during the write