Top Description Methods
org.python.core

public Interface BufferProtocol

Known Direct Subinterfaces
org.python.core.PyBuffer
Known Direct Implementers
org.python.core.Py2kBuffer, org.python.core.PyArray, org.python.core.PyMemoryView, org.python.core.PyByteArray, org.python.core.PyString

Interface marking an object as capable of exposing its internal state as a PyBuffer.

A few objects implement BufferProtocol (e.g. by inheritance) but cannot actually provide their value as a PyBuffer. These should throw ClassCastException, permitting the idiom:

    try (PyBuffer buf = ((BufferProtocol) obj).getBuffer(PyBUF.SIMPLE)) {
        ... // Do something with buf
    } catch (ClassCastException e) {
        ... // expected bytes object or buffer not obj.getType()
    }
The catch is executed identically whether the cause is the explicit cast of obj or getBuffer, and the try-with-resources releases the buffer if one was obtained.

Method Summary

Modifier and TypeMethod and Description
public PyBuffer

Returns:

exported buffer
getBuffer
(int
specifying features demanded and the navigational capabilities of the consumer
flags
)

Method by which the consumer requests the buffer from the exporter.

Method Detail

getBufferback to summary
public PyBuffer getBuffer(int flags) throws PyException, ClassCastException

Method by which the consumer requests the buffer from the exporter. The consumer provides information on its ability to understand buffer navigation. Each consumer requesting a buffer in this way, when it has finished using it, should make a corresponding call to PyBuffer#release() on the buffer it obtained, or PyBuffer#close() using try-with-resources, since some objects alter their behaviour while buffers are exported.

Parameters
flags:int

specifying features demanded and the navigational capabilities of the consumer

Returns:PyBuffer

exported buffer

Exceptions
PyException:
BufferError when expectations do not correspond with the buffer
ClassCastException:
when the object only formally implements BufferProtocol