Class SimpleNIOBuffer
- All Implemented Interfaces:
AutoCloseable,BufferProtocol,PyBUF,PyBuffer
java.nio.ByteBuffer of one-byte items.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.python.core.PyBuffer
PyBuffer.Pointer -
Field Summary
Fields inherited from interface org.python.core.PyBUF
ANY_CONTIGUOUS, AS_ARRAY, C_CONTIGUOUS, CONTIG, CONTIG_RO, CONTIGUITY, F_CONTIGUOUS, FORMAT, FULL, FULL_RO, INDIRECT, IS_C_CONTIGUOUS, IS_F_CONTIGUOUS, MAX_NDIM, NAVIGATION, ND, RECORDS, RECORDS_RO, SIMPLE, STRIDED, STRIDED_RO, STRIDES, WRITABLE -
Constructor Summary
ConstructorsConstructorDescriptionSimpleNIOBuffer(int flags, BufferProtocol obj, ByteBuffer storage) Provide an instance ofSimpleNIOBuffer, on the entirety of aByteBuffer, meeting the consumer's expectations as expressed in theflagsargument, which is checked against the capabilities of the buffer type.SimpleNIOBuffer(int flags, BufferProtocol obj, ByteBuffer storage, int index0, int size) Provide an instance ofSimpleNIOBuffer, on a slice of aByteBuffer, meeting the consumer's expectations as expressed in theflagsargument, which is checked against the capabilities of the buffer type. -
Method Summary
Modifier and TypeMethodDescriptionfinal intbyteIndex(int index) Convert an item index (for a one-dimensional buffer) to an absolute byte index in the storage shared by the exporter.getBufferSlice(int flags, int start, int count) Equivalent toPyBuffer.getBufferSlice(int, int, int, int)with stride 1.getBufferSlice(int flags, int start, int count, int stride) Get aPyBufferthat 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.intgetLen()The total number of bytes represented by the view, which will be the product of the elements of theshapearray, and the item size in bytes.Methods inherited from class org.python.core.buffer.BaseNIOBuffer
byteIndex, copyFrom, copyTo, copyTo, getBufMethods inherited from class org.python.core.buffer.Base1DBuffer
isContiguousMethods inherited from class org.python.core.buffer.BaseBuffer
byteAt, byteAt, close, copyFrom, copyTo, getBuffer, getBufferAgain, getFormat, getItemsize, getNdim, getNIOByteBuffer, getObj, getPointer, getPointer, getShape, getStrides, getSuboffsets, hasArray, intAt, intAt, isReadonly, isReleased, release, storeAt, storeAt, toString
-
Constructor Details
-
SimpleNIOBuffer
public SimpleNIOBuffer(int flags, BufferProtocol obj, ByteBuffer storage, int index0, int size) throws PyException, ArrayIndexOutOfBoundsException, NullPointerException Provide an instance ofSimpleNIOBuffer, on a slice of aByteBuffer, meeting the consumer's expectations as expressed in theflagsargument, which is checked against the capabilities of the buffer type. No reference will be kept to theByteBufferpassed in. (It is duplicated.)- Parameters:
flags- consumer requirementsobj- exporting object (ornull)storage- theByteBufferwrapping the exported object stateindex0- offset where the data starts in that buffer (item[0])size- the number of bytes occupied- Throws:
NullPointerException- ifstorageis nullArrayIndexOutOfBoundsException- ifindex0andsizeare inconsistent withstorage.lengthPyException-BufferErrorwhen expectations do not correspond with the type
-
SimpleNIOBuffer
public SimpleNIOBuffer(int flags, BufferProtocol obj, ByteBuffer storage) throws PyException, NullPointerException Provide an instance ofSimpleNIOBuffer, on the entirety of aByteBuffer, meeting the consumer's expectations as expressed in theflagsargument, which is checked against the capabilities of the buffer type. No reference will be kept to theByteBufferpassed in. (It is duplicated.)- Parameters:
flags- consumer requirementsobj- exporting object (ornull)storage- theByteBufferwrapping the exported object state- Throws:
NullPointerException- ifstorageis nullPyException-BufferErrorwhen expectations do not correspond with the type
-
-
Method Details
-
getLen
public int getLen()The total number of bytes represented by the view, which will be the product of the elements of theshapearray, and the item size in bytes.SimpleNIOBufferprovides an implementation optimised for contiguous bytes in one-dimension.- Specified by:
getLenin interfacePyBUF- Overrides:
getLenin classBase1DBuffer- Returns:
- the total number of bytes represented.
-
byteIndex
Description copied from interface:PyBufferConvert an item index (for a one-dimensional buffer) to an absolute byte index in the storage shared by the exporter. The storage exported as aPyBufferis a linearly-indexed sequence of bytes, although it may not actually be a heap-allocated Javabyte[]object. The purpose of this method is to allow the exporter to define the relationship between the item index (as used inPyBuffer.byteAt(int)) and the byte-index (as used with theByteBufferreturned byPyBuffer.getNIOByteBuffer()). SeePyBuffer.byteIndex(int[])for discussion of the multi-dimensional case.- Specified by:
byteIndexin interfacePyBuffer- Overrides:
byteIndexin classBaseBuffer- Parameters:
index- item-index from consumer- Returns:
- corresponding byte-index in actual storage
- Throws:
IndexOutOfBoundsException
-
getBufferSlice
Description copied from interface:PyBufferEquivalent toPyBuffer.getBufferSlice(int, int, int, int)with stride 1.- Specified by:
getBufferSlicein interfacePyBuffer- Overrides:
getBufferSlicein classBaseBuffer- Parameters:
flags- specifying features demanded and the navigational capabilities of the consumerstart- index in the current buffercount- number of items in the required slice- Returns:
- a buffer representing the slice
-
getBufferSlice
Get aPyBufferthat 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 aPyBufferwithgetBufferSlicemust release it withPyBuffer.release()just as if it had been obtained withPyBuffer.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 bythis.getPointer(i). A request for a slice wherestart= s,count= N andstride= 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
startindex,countandstridewill be translated from the arguments given, through this buffer's stride and item size. The caller always expressesstartandstridesin terms of the abstract view of this buffer.SimpleNIOBufferprovides 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- specifying features demanded and the navigational capabilities of the consumerstart- index in the current buffercount- number of items in the required slicestride- index-distance in the current buffer between consecutive items in the slice- Returns:
- a buffer representing the slice
-