public interface BufferProtocol
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.Modifier and Type | Method and Description |
---|---|
PyBuffer |
getBuffer(int flags)
Method by which the consumer requests the buffer from the exporter.
|
PyBuffer getBuffer(int flags) throws PyException, java.lang.ClassCastException
PyBuffer.release()
on the buffer it obtained, or PyBuffer.close()
using
try-with-resources, since some objects alter their behaviour while buffers are exported.flags
- specifying features demanded and the navigational capabilities of the consumerPyException
- BufferError
when expectations do not correspond with the bufferjava.lang.ClassCastException
- when the object only formally implements BufferProtocol