Пример #1
0
  private void loadPart(final int blockIndex) {
    int size = blockSize;
    int fileOffset = blockIndex * blockSize;
    if ((blockIndex + 1) * blockSize > srcReference.getSize()) {
      size = srcReference.getSize() - blockIndex * blockSize;
    }

    // TODO: Validate file part load ordering
    inputFile
        .read(fileOffset, size)
        .then(
            filePart -> {
              if (isCompleted) {
                return;
              }
              if (LOG) {
                Log.d(TAG, "Block #" + blockIndex + " read");
              }

              if (isWriteToDestProvider) {
                if (!outputFile.write(
                    fileOffset, filePart.getContents(), 0, filePart.getPartLength())) {
                  if (LOG) {
                    Log.w(TAG, "write #" + blockIndex + " error");
                  }
                  reportError();
                  return;
                }
              }

              crc32.update(filePart.getContents(), 0, filePart.getPartLength());

              if (LOG) {
                Log.d(TAG, "Starting block upload #" + blockIndex);
              }

              uploadCount++;
              uploadPart(blockIndex, filePart.getContents(), 0);
              checkQueue();
            })
        .failure(
            e -> {
              if (isCompleted) {
                return;
              }
              if (LOG) {
                Log.w(TAG, "Block #" + blockIndex + " read failure");
              }
              reportError();
            });
  }