@Override
  public int write(final ByteBuffer b) throws IOException {
    ensureOpen();
    int wanted = b.remaining();
    final int possibleWithoutResize = size - position;
    if (wanted > possibleWithoutResize) {
      final int newSize = position + wanted;
      if (newSize < 0) { // overflow
        resize(Integer.MAX_VALUE);
        wanted = Integer.MAX_VALUE - position;
      } else {
        resize(newSize);
      }
    }
    b.get(data, position, wanted);
    position += wanted;
    if (size < position) {
      size = position;
    }
    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