@Nullable
  public byte[] downloadBytes(final int maxBytesToRead) throws AppleContentException {
    final byte[] buffer = new byte[maxBytesToRead];

    try {
      int bytesRead = IOUtils.read(connection.getInputStream(), buffer);
      // re-try if a 301 is received, otherwise throw an exception
      if (connection.getResponseCode() != HttpStatus.SC_OK) {
        if (connection.getResponseCode() == HttpStatus.SC_MOVED_PERMANENTLY) {
          final String newUrl = connection.getHeaderField(HttpHeaders.LOCATION);
          URL urlObject = new URL(newUrl);
          connection = (HttpURLConnection) urlObject.openConnection();
          connection.setRequestProperty("Transfer-Encoding", "chunked");
          connection.setRequestProperty("content-type", "application/octet-stream");
          connection.setDoOutput(true);
          connection.setRequestMethod("GET");

          bytesRead = IOUtils.read(connection.getInputStream(), buffer);

          if (connection.getResponseCode() != HttpStatus.SC_OK) {
            throw new IOException(
                "Error response code when trying to download content "
                    + connection.getResponseCode());
          }
        } else {
          throw new IOException(
              "Error response code when trying to download content "
                  + connection.getResponseCode());
        }
      }
      if (bytesRead < maxBytesToRead) {
        connection.disconnect();
        if (bytesRead <= 0) {
          return null;
        } else {
          final byte[] truncatedBuffer = Arrays.copyOf(buffer, bytesRead);
          return truncatedBuffer;
        }
      }
      return buffer;
    } catch (IOException e) {
      monitor.severe(() -> "Error when downloading from Content", e);
      connection.disconnect();
      throw new AppleContentException("Error when downloading from Content", e);
    }
  }
Attempts to read the given number of bytes from the url specified in the constructor. If less
than the given number of bytes are available, return a truncated buffer. If no bytes are
available, return null.

@param maxBytesToRead
@return bytes read from url (or null if none can be read)
@throws AppleContentException
extensions/data-transfer/portability-data-transfer-apple/src/main/java/org/datatransferproject/datatransfer/apple/photos/streaming/StreamingContentClient.java