Package io.servicetalk.concurrent.api
Interface ByteArrayMapper<T>
- Type Parameters:
T
- Type of the result of this mapper
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A mapper to transform
byte[]
buffer regions into a desired type T
.-
Method Summary
Modifier and TypeMethodDescriptionmap
(byte[] buffer, int offset, int length) Maps a specifiedbyte[]
buffer region into aT
.default int
Returns the maximum allowed buffer size for themap(byte[], int, int)
operation.static ByteArrayMapper<byte[]>
Mapper from the buffer region to an independentbyte[]
buffer.static ByteArrayMapper<byte[]>
toByteArray
(int maxBufferSize) Mapper from the buffer region to an independentbyte[]
buffer.
-
Method Details
-
map
Maps a specifiedbyte[]
buffer region into aT
.The mapper can operate only within the specified region of the
buffer
, which can be safely used without a need to copy data. Access to other parts of the buffer may lead to unexpected results and due care should be taken to avoid leaking that data through the returned typeT
.- Parameters:
buffer
-byte[]
buffer with dataoffset
- the offset of the regionlength
- the length of the region- Returns:
- result of type
T
-
maxBufferSize
default int maxBufferSize()Returns the maximum allowed buffer size for themap(byte[], int, int)
operation.Must be a positive number.
- Returns:
- the maximum allowed buffer size for the
map(byte[], int, int)
operation
-
toByteArray
Mapper from the buffer region to an independentbyte[]
buffer.Returns
toByteArray(int)
with defaultmaxBufferSize()
.- Returns:
- a mapper from the buffer region to an independent
byte[]
buffer
-
toByteArray
Mapper from the buffer region to an independentbyte[]
buffer.Returns the original
byte[]
buffer as-is if it was completely full of data or allocates a new buffer for the specified length and copies data. Returnedbyte[]
buffer is always completely full.- Parameters:
maxBufferSize
- the value formaxBufferSize()
- Returns:
- a mapper from the buffer region to an independent
byte[]
buffer
-