コード例 #1
0
ファイル: UploadTask.java プロジェクト: y0ke/actor-platform
  private void checkQueue() {
    if (isCompleted) {
      return;
    }

    if (nextBlock == blocksCount && uploadCount == 0) {
      if (LOG) {
        Log.d(TAG, "Completing...");
      }
      long crc = crc32.getValue();
      if (LOG) {
        Log.d(TAG, "Src #" + crc);

        Log.d(TAG, "Closing files...");
      }
      inputFile.close();
      if (isWriteToDestProvider) {
        outputFile.close();
      }

      request(
          new RequestCommitFileUpload(uploadConfig, fileName),
          new RpcCallback<ResponseCommitFileUpload>() {
            @Override
            public void onResult(ResponseCommitFileUpload response) {
              if (LOG) {
                Log.d(TAG, "Upload completed...");
              }

              FileReference location =
                  new FileReference(
                      response.getUploadedFileLocation(), fileName, srcReference.getSize());

              if (isWriteToDestProvider || alreadyInTemp) {
                FileSystemReference reference =
                    Storage.commitTempFile(
                        alreadyInTemp ? srcReference : destReference,
                        location.getFileId(),
                        location.getFileName());
                reportComplete(location, reference);
              } else {
                reportComplete(location, srcReference);
              }
            }

            @Override
            public void onError(RpcException e) {
              if (LOG) {
                Log.w(TAG, "Upload complete error");
              }
              reportError();
            }
          });
      return;
    }

    if (nextBlock < blocksCount && uploadCount < SIM_BLOCKS_COUNT) {
      loadPart(nextBlock++);
    }
  }
コード例 #2
0
ファイル: UploadTask.java プロジェクト: y0ke/actor-platform
  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();
            });
  }