docs: protected byte[] toByteArray(HttpEntity entity, int maxBytes) throws IOException {
          if (entity == null) {
              return new byte[0];
          }
          try (InputStream is = entity.getContent()) {
              int size = (int) entity.getContentLength();
              int readBufferLength = size;
  
              if (readBufferLength <= 0) {
                  readBufferLength = 4096;
              }
              // in case when the maxBytes is less than the actual page size
              readBufferLength = Math.min(readBufferLength, maxBytes);
  
              // We allocate the buffer with either the actual size of the entity (if available)
              // or with the default 4KiB if the server did not return a value to avoid allocating
              // the full maxBytes (for the cases when the actual size will be smaller than maxBytes).
              ByteArrayBuffer buffer = new ByteArrayBuffer(readBufferLength);
  
              byte[] tmpBuff = new byte[4096];
              int dataLength;
  
              while ((dataLength = is.read(tmpBuff)) != -1) {
                  if (maxBytes > 0 && (buffer.length() + dataLength) > maxBytes) {
                      truncated = true;
                      dataLength = maxBytes - buffer.length();
                  }
                  buffer.append(tmpBuff, 0, dataLength);
                  if (truncated) {
                      break;
                  }
              }
              return buffer.toByteArray();
          }
      }