Top Description Inners Fields Constructors Methods
org.python.core.buffer

public Class SimpleNIOBuffer

extends BaseNIOBuffer
Class Inheritance
Known Direct Subclasses
org.python.core.buffer.SimpleNIOBuffer.SimpleView
Imports
java.nio.ByteBuffer, org.python.core.BufferProtocol, .PyBuffer, .PyException

Buffer API over a read-only one-dimensional java.nio.ByteBuffer of one-byte items.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
SimpleNIOBuffer.SimpleView

A SimpleNIOBuffer.SimpleView represents a contiguous subsequence of another SimpleNIOBuffer.

Field Summary

Inherited from org.python.core.buffer.BaseNIOBuffer:
storage

Constructor Summary

AccessConstructor and Description
protected
SimpleNIOBuffer(BufferProtocol
exporting object (or null)
obj
,
ByteBuffer
the ByteBuffer wrapping the exported object state.

Note

this PyBuffer keeps a reference and may manipulate the position, mark and limit hereafter. Use ByteBuffer#duplicate() to give it an isolated copy.

storage
,
int
offset where the data starts in that array (item[0])
index0
,
int
the number of bytes occupied
size
)

Provide an instance of SimpleNIOBuffer with navigation variables initialised, for sub-class use.

public
SimpleNIOBuffer(int
consumer requirements
flags
,
BufferProtocol
exporting object (or null)
obj
,
ByteBuffer
the ByteBuffer wrapping the exported object state
storage
,
int
offset where the data starts in that buffer (item[0])
index0
,
int
the number of bytes occupied
size
)

Provide an instance of SimpleNIOBuffer, on a slice of a ByteBuffer, meeting the consumer's expectations as expressed in the flags argument, which is checked against the capabilities of the buffer type.

protected
SimpleNIOBuffer(BufferProtocol
exporting object (or null)
obj
,
ByteBuffer
the ByteBuffer wrapping the exported object state.

Note

this PyBuffer keeps a reference and may manipulate the position, mark and limit hereafter. Use ByteBuffer#duplicate() to give it an isolated copy.

storage
)

Provide an instance of SimpleNIOBuffer, on the entirety of a ByteBuffer, with navigation variables initialised, for sub-class use.

public
SimpleNIOBuffer(int
consumer requirements
flags
,
BufferProtocol
exporting object (or null)
obj
,
ByteBuffer
the ByteBuffer wrapping the exported object state
storage
)

Provide an instance of SimpleNIOBuffer, on the entirety of a ByteBuffer, meeting the consumer's expectations as expressed in the flags argument, which is checked against the capabilities of the buffer type.

Method Summary

Modifier and TypeMethod and Description
public final int
byteIndex(int
item-index from consumer
index
)

Overrides org.python.core.buffer.BaseBuffer.byteIndex.

Implements org.python.core.PyBuffer.byteIndex.

Convert an item index (for a one-dimensional buffer) to an absolute byte index in the storage shared by the exporter.

public PyBuffer
getBufferSlice(int
specifying features demanded and the navigational capabilities of the consumer
flags
,
int
index in the current buffer
start
,
int
number of items in the required slice
count
)

Overrides org.python.core.buffer.BaseBuffer.getBufferSlice.

Implements org.python.core.PyBuffer.getBufferSlice.

Equivalent to getBufferSlice(int, int, int, int) with stride 1.

public PyBuffer
getBufferSlice(int
specifying features demanded and the navigational capabilities of the consumer
flags
,
int
index in the current buffer
start
,
int
number of items in the required slice
count
,
int
index-distance in the current buffer between consecutive items in the slice
stride
)

Implements org.python.core.PyBuffer.getBufferSlice.

Get a PyBuffer that represents a slice of the current one described in terms of a start index, number of items to include in the slice, and the stride in the current buffer.

public int
getLen()

Overrides org.python.core.buffer.Base1DBuffer.getLen.

Implements org.python.core.PyBUF.getLen.

The total number of bytes represented by the view, which will be the product of the elements of the shape array, and the item size in bytes.

Inherited from org.python.core.buffer.BaseNIOBuffer:
byteAtImplbyteIndexcopyFromcopyFromcopyTocopyTocopyTogetBufgetNIOByteBufferImplstoreAtImpl

Constructor Detail

SimpleNIOBufferback to summary
protected SimpleNIOBuffer(BufferProtocol obj, ByteBuffer storage, int index0, int size) throws PyException, ArrayIndexOutOfBoundsException

Provide an instance of SimpleNIOBuffer with navigation variables initialised, for sub-class use. The buffer (storage, index0), and the shape array will be initialised from the arguments (which are checked for range). The strides is set for (one-byte) unit stride. Only the call to checkRequestFlags(int), passing the consumer's request flags, really remains for the sub-class constructor to do.

super(storage.duplicate(), index0, size);
checkRequestFlags(flags);        // Check request is compatible with type
Parameters
obj:BufferProtocol

exporting object (or null)

storage:ByteBuffer

the ByteBuffer wrapping the exported object state.

Note

this PyBuffer keeps a reference and may manipulate the position, mark and limit hereafter. Use ByteBuffer#duplicate() to give it an isolated copy.

index0:int

offset where the data starts in that array (item[0])

size:int

the number of bytes occupied

Exceptions
ArrayIndexOutOfBoundsException:
if index0 and size are inconsistent with storage.capacity()
NullPointerException:
if storage is null
SimpleNIOBufferback to summary
public SimpleNIOBuffer(int flags, BufferProtocol obj, ByteBuffer storage, int index0, int size) throws PyException, ArrayIndexOutOfBoundsException, NullPointerException

Provide an instance of SimpleNIOBuffer, on a slice of a ByteBuffer, meeting the consumer's expectations as expressed in the flags argument, which is checked against the capabilities of the buffer type. No reference will be kept to the ByteBuffer passed in. (It is duplicated.)

Parameters
flags:int

consumer requirements

obj:BufferProtocol

exporting object (or null)

storage:ByteBuffer

the ByteBuffer wrapping the exported object state

index0:int

offset where the data starts in that buffer (item[0])

size:int

the number of bytes occupied

Exceptions
PyException:
BufferError when expectations do not correspond with the type
ArrayIndexOutOfBoundsException:
if index0 and size are inconsistent with storage.length
NullPointerException:
if storage is null
SimpleNIOBufferback to summary
protected SimpleNIOBuffer(BufferProtocol obj, ByteBuffer storage) throws NullPointerException

Provide an instance of SimpleNIOBuffer, on the entirety of a ByteBuffer, with navigation variables initialised, for sub-class use. The buffer ( storage, index0), and the navigation (shape array) will be initialised from the argument.

Parameters
obj:BufferProtocol

exporting object (or null)

storage:ByteBuffer

the ByteBuffer wrapping the exported object state.

Note

this PyBuffer keeps a reference and may manipulate the position, mark and limit hereafter. Use ByteBuffer#duplicate() to give it an isolated copy.

Exceptions
NullPointerException:
if storage is null
SimpleNIOBufferback to summary
public SimpleNIOBuffer(int flags, BufferProtocol obj, ByteBuffer storage) throws PyException, NullPointerException

Provide an instance of SimpleNIOBuffer, on the entirety of a ByteBuffer, meeting the consumer's expectations as expressed in the flags argument, which is checked against the capabilities of the buffer type. No reference will be kept to the ByteBuffer passed in. (It is duplicated.)

Parameters
flags:int

consumer requirements

obj:BufferProtocol

exporting object (or null)

storage:ByteBuffer

the ByteBuffer wrapping the exported object state

Exceptions
PyException:
BufferError when expectations do not correspond with the type
NullPointerException:
if storage is null

Method Detail

byteIndexback to summary
public final int byteIndex(int index) throws IndexOutOfBoundsException

Overrides org.python.core.buffer.BaseBuffer.byteIndex.

Implements org.python.core.PyBuffer.byteIndex.

Doc from org.python.core.PyBuffer.byteIndex.

Convert an item index (for a one-dimensional buffer) to an absolute byte index in the storage shared by the exporter. The storage exported as a PyBuffer is a linearly-indexed sequence of bytes, although it may not actually be a heap-allocated Java byte[] object. The purpose of this method is to allow the exporter to define the relationship between the item index (as used in byteAt(int)) and the byte-index (as used with the ByteBuffer returned by getNIOByteBuffer()). See byteIndex(int[]) for discussion of the multi-dimensional case.

Parameters
index:int

item-index from consumer

Returns:int

corresponding byte-index in actual storage

Annotations
@Override

getBufferSliceback to summary
public PyBuffer getBufferSlice(int flags, int start, int count)

Overrides org.python.core.buffer.BaseBuffer.getBufferSlice.

Implements org.python.core.PyBuffer.getBufferSlice.

Doc from org.python.core.PyBuffer.getBufferSlice.

Equivalent to getBufferSlice(int, int, int, int) with stride 1.

Parameters
flags:int

specifying features demanded and the navigational capabilities of the consumer

start:int

index in the current buffer

count:int

number of items in the required slice

Returns:PyBuffer

a buffer representing the slice

Annotations
@Override

getBufferSliceback to summary
public PyBuffer getBufferSlice(int flags, int start, int count, int stride)

Implements org.python.core.PyBuffer.getBufferSlice.

Doc from org.python.core.PyBuffer.getBufferSlice.

Get a PyBuffer that represents a slice of the current one described in terms of a start index, number of items to include in the slice, and the stride in the current buffer. A consumer that obtains a PyBuffer with getBufferSlice must release it with PyBuffer#release just as if it had been obtained with PyBuffer#getBuffer(int)

Suppose that x(i) denotes the ith element of the current buffer, that is, the byte retrieved by this.byteAt(i) or the unit indicated by this.getPointer(i). A request for a slice where start = s, count = N and stride = m, results in a buffer y such that y(k) = x(s+km) where k=0..(N-1). In Python terms, this is the slice x[s : s+(N-1)m+1 : m] (if m>0) or the slice x[s : s+(N-1)m-1 : m] (if m<0). Implementations should check that this range is entirely within the current buffer.

In a simple buffer backed by a contiguous byte array, the result is a strided PyBuffer on the same storage but where the offset is adjusted by s and the stride is as supplied. If the current buffer is already strided and/or has an item size larger than single bytes, the new start index, count and stride will be translated from the arguments given, through this buffer's stride and item size. The caller always expresses start and strides in terms of the abstract view of this buffer.

SimpleNIOBuffer provides an implementation for slicing contiguous bytes in one dimension. In that case, x(i) = u(r+i) for i = 0..L-1 where u is the underlying buffer, and r and L are the start and count with which x was created from u. Thus y(k) = u(r+s+km), that is, the composite offset is r+s and the stride is m.

Parameters
flags:int

specifying features demanded and the navigational capabilities of the consumer

start:int

index in the current buffer

count:int

number of items in the required slice

stride:int

index-distance in the current buffer between consecutive items in the slice

Returns:PyBuffer

a buffer representing the slice

Annotations
@Override

getLenback to summary
public int getLen()

Overrides org.python.core.buffer.Base1DBuffer.getLen.

Implements org.python.core.PyBUF.getLen.

Doc from org.python.core.PyBUF.getLen.

The total number of bytes represented by the view, which will be the product of the elements of the shape array, and the item size in bytes.

SimpleNIOBuffer provides an implementation optimised for contiguous bytes in one-dimension.

Returns:int

the total number of bytes represented.

Annotations
@Override

org.python.core.buffer back to summary

pack-priv Class SimpleNIOBuffer.SimpleView

extends SimpleNIOBuffer
Class Inheritance

A SimpleNIOBuffer.SimpleView represents a contiguous subsequence of another SimpleNIOBuffer.

Field Summary

Modifier and TypeField and Description
pack-priv PyBuffer
root

The buffer on which this is a slice view

Constructor Summary

AccessConstructor and Description
public
SimpleView(PyBuffer
buffer which will be acquired and must be released ultimately
root
,
int
the request flags of the consumer that requested the slice
flags
,
ByteBuffer
ByteBuffer wrapping exported data (no reference kept)
storage
,
int
where the data starts in that buffer (item[0])
offset
,
int
the number of items in the sliced view
count
)

Construct a slice of a SimpleNIOBuffer.

Method Summary

Modifier and TypeMethod and Description
protected PyBuffer
getRoot()

Overrides org.python.core.buffer.BaseBuffer.getRoot.

Some PyBuffers, those created by slicing a PyBuffer, are related to a root PyBuffer.

Inherited from org.python.core.buffer.SimpleNIOBuffer:
byteIndexgetBufferSlicegetBufferSlicegetLen

Field Detail

rootback to summary
pack-priv PyBuffer root

The buffer on which this is a slice view

Constructor Detail

SimpleViewback to summary
public SimpleView(PyBuffer root, int flags, ByteBuffer storage, int offset, int count)

Construct a slice of a SimpleNIOBuffer.

Parameters
root:PyBuffer

buffer which will be acquired and must be released ultimately

flags:int

the request flags of the consumer that requested the slice

storage:ByteBuffer

ByteBuffer wrapping exported data (no reference kept)

offset:int

where the data starts in that buffer (item[0])

count:int

the number of items in the sliced view

Method Detail

getRootback to summary
protected PyBuffer getRoot()

Overrides org.python.core.buffer.BaseBuffer.getRoot.

Doc from org.python.core.buffer.BaseBuffer.getRoot.

Some PyBuffers, those created by slicing a PyBuffer, are related to a root PyBuffer. During creation of such a slice, we need to supply a value for this root. If the present object is not itself a slice, this root is the object itself; if the buffer is already a slice, it is the root it was given at creation time. Often this is the only difference between a slice-view and a directly-exported buffer. Override this method in slices to return the root buffer of the slice.

Returns:PyBuffer

this buffer (or the root buffer if this is a sliced view)

Annotations
@Override