@Override
  public int read(final ByteBuffer buf) throws IOException {
    ensureOpen();
    int wanted = buf.remaining();
    final int possible = size - position;
    if (possible <= 0) {
      return -1;
    }
    if (wanted > possible) {
      wanted = possible;
    }
    buf.put(data, position, wanted);
    position += wanted;
    return wanted;
  }
Truncates the entity, to which this channel is connected, to the given size.

<p>
This method violates the contract of {@link SeekableByteChannel#truncate} as it will not throw any exception when
invoked on a closed channel.
</p>

@throws IllegalArgumentException if size is negative or bigger than the maximum of a Java integer
planetiler-core/src/main/java/com/onthegomap/planetiler/util/SeekableInMemoryByteChannel.java