public class

MemoryPooledByteBuffer

extends Object
implements PooledByteBuffer
java.lang.Object
   ↳ com.facebook.imagepipeline.memory.MemoryPooledByteBuffer

Class Overview

An implementation of PooledByteBuffer that uses (MemoryChunk) to store data

Summary

Public Constructors
MemoryPooledByteBuffer(CloseableReference<MemoryChunk> bufRef, int size)
Public Methods
synchronized void close()
Closes this instance, and releases the underlying buffer to the pool.
synchronized ByteBuffer getByteBuffer()
Gets the underlying ByteBuffer backing this buffer if present, else null.
synchronized long getNativePtr()
Gets the pointer to native memory backing this buffer if present
synchronized boolean isClosed()
Check if this instance has already been closed
synchronized int read(int offset, byte[] buffer, int bufferOffset, int length)
Read consecutive bytes.
synchronized byte read(int offset)
Read byte at given offset
synchronized int size()
Gets the size of the ByteBuffer if it is valid.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.common.memory.PooledByteBuffer
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public Constructors

public MemoryPooledByteBuffer (CloseableReference<MemoryChunk> bufRef, int size)

Public Methods

public synchronized void close ()

Closes this instance, and releases the underlying buffer to the pool. Once the ByteBuffer has been closed, subsequent operations (especially getStream() will fail. Note: It is not an error to close an already closed ByteBuffer

public synchronized ByteBuffer getByteBuffer ()

Gets the underlying ByteBuffer backing this buffer if present, else null.

public synchronized long getNativePtr ()

Gets the pointer to native memory backing this buffer if present

Returns
  • the pointer
Throws
UnsupportedOperationException

public synchronized boolean isClosed ()

Check if this instance has already been closed

Returns
  • true, if the instance has been closed

public synchronized int read (int offset, byte[] buffer, int bufferOffset, int length)

Read consecutive bytes.

Parameters
offset the position in the PooledByteBuffer of the first byte to read
buffer the byte array where read bytes will be copied to
bufferOffset the position within the buffer of the first copied byte
length number of bytes to copy
Returns
  • number of bytes copied

public synchronized byte read (int offset)

Read byte at given offset

Returns
  • byte at given offset

public synchronized int size ()

Gets the size of the ByteBuffer if it is valid. Otherwise, an exception is raised

Returns
  • the size of the ByteBuffer if it is not closed.
Throws
ClosedException}