docs: public ByteBuffer readToByteBuffer(int max) throws IOException {
          Validate.isTrue(max >= 0, "maxSize must be 0 (unlimited) or larger");
          final boolean localCapped = max > 0; // still possibly capped in total stream
          final int bufferSize = localCapped && max < DefaultSize ? max : DefaultSize;
          final byte[] readBuffer = new byte[bufferSize];
          final ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);
  
          int read;
          int remaining = max;
  
          while (true) {
              read = read(readBuffer);
              if (read == -1) break;
              if (localCapped) { // this local byteBuffer cap may be smaller than the overall maxSize (like when reading first bytes)
                  if (read >= remaining) {
                      outStream.write(readBuffer, 0, remaining);
                      break;
                  }
                  remaining -= read;
              }
              outStream.write(readBuffer, 0, read);
          }
          return ByteBuffer.wrap(outStream.toByteArray());
      }