private static @NotNull ByteBuffer ensureLimit(ByteBuffer buffer,
                                                 int requiredLimit) {
    if (buffer.capacity() >= requiredLimit) {
      return buffer.limit(Math.max(buffer.limit(), requiredLimit));
    }
    else {
      return ByteBuffer.allocate(requiredLimit)
        .order(buffer.order())
        .position(buffer.position());
    }
  }
private static @NotNull ByteBuffer ensureLimit(ByteBuffer buffer,
                                                 int requiredLimit)