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.

@FunctionalInterface public interface ByteArrayMapper<T>
A mapper to transform byte[] buffer regions into a desired type T.
  • Method Summary

    Modifier and Type
    Method
    Description
    map(byte[] buffer, int offset, int length)
    Maps a specified byte[] buffer region into a T.
    default int
    Returns the maximum allowed buffer size for the map(byte[], int, int) operation.
    static ByteArrayMapper<byte[]>
    Mapper from the buffer region to an independent byte[] buffer.
    static ByteArrayMapper<byte[]>
    toByteArray(int maxBufferSize)
    Mapper from the buffer region to an independent byte[] buffer.
  • Method Details

    • map

      T map(byte[] buffer, int offset, int length)
      Maps a specified byte[] buffer region into a T.

      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 type T.

      Parameters:
      buffer - byte[] buffer with data
      offset - the offset of the region
      length - the length of the region
      Returns:
      result of type T
    • maxBufferSize

      default int maxBufferSize()
      Returns the maximum allowed buffer size for the map(byte[], int, int) operation.

      Must be a positive number.

      Returns:
      the maximum allowed buffer size for the map(byte[], int, int) operation
    • toByteArray

      static ByteArrayMapper<byte[]> toByteArray()
      Mapper from the buffer region to an independent byte[] buffer.

      Returns toByteArray(int) with default maxBufferSize().

      Returns:
      a mapper from the buffer region to an independent byte[] buffer
    • toByteArray

      static ByteArrayMapper<byte[]> toByteArray(int maxBufferSize)
      Mapper from the buffer region to an independent byte[] 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. Returned byte[] buffer is always completely full.

      Parameters:
      maxBufferSize - the value for maxBufferSize()
      Returns:
      a mapper from the buffer region to an independent byte[] buffer