/** * The uploading progress listener. Its progressChanged API is called by the SDK when there's an update. */ staticclassPutObjectProgressListenerimplementsProgressListener{
@Override publicvoidprogressChanged(ProgressEvent progressEvent){ long bytes = progressEvent.getBytes(); ProgressEventType eventType = progressEvent.getEventType(); switch (eventType) { case TRANSFER_STARTED_EVENT: System.out.println("Start to upload......"); break;
case REQUEST_CONTENT_LENGTH_EVENT: this.totalBytes = bytes; System.out.println(this.totalBytes + " bytes in total will be uploaded to OSS"); break;
case REQUEST_BYTE_TRANSFER_EVENT: this.bytesWritten += bytes; if (this.totalBytes != -1) { int percent = (int) (this.bytesWritten * 100.0 / this.totalBytes); System.out.println(bytes + " bytes have been written at this time, upload progress: " + percent + "%(" + this.bytesWritten + "/" + this.totalBytes + ")"); } else { System.out.println(bytes + " bytes have been written at this time, upload ratio: unknown" + "(" + this.bytesWritten + "/...)"); } break;
case TRANSFER_COMPLETED_EVENT: this.succeed = true; System.out.println("Succeed to upload, " + this.bytesWritten + " bytes have been transferred in total"); break;
case TRANSFER_FAILED_EVENT: System.out.println("Failed to upload, " + this.bytesWritten + " bytes have been transferred"); break;
default: break; } }
publicbooleanisSucceed(){ return succeed; } }
/** * The downloading progress listener. Its progressChanged API is called by the SDK when there's an update. */ staticclassGetObjectProgressListenerimplementsProgressListener{
@Override publicvoidprogressChanged(ProgressEvent progressEvent){ long bytes = progressEvent.getBytes(); ProgressEventType eventType = progressEvent.getEventType(); switch (eventType) { case TRANSFER_STARTED_EVENT: System.out.println("Start to download......"); break;
case RESPONSE_CONTENT_LENGTH_EVENT: this.totalBytes = bytes; System.out.println(this.totalBytes + " bytes in total will be downloaded to a local file"); break;
case RESPONSE_BYTE_TRANSFER_EVENT: this.bytesRead += bytes; if (this.totalBytes != -1) { int percent = (int) (this.bytesRead * 100.0 / this.totalBytes); System.out.println(bytes + " bytes have been read at this time, download progress: " + percent + "%(" + this.bytesRead + "/" + this.totalBytes + ")"); } else { System.out.println(bytes + " bytes have been read at this time, download ratio: unknown" + "(" + this.bytesRead + "/...)"); } break;
case TRANSFER_COMPLETED_EVENT: this.succeed = true; System.out.println("Succeed to download, " + this.bytesRead + " bytes have been transferred in total"); break;
case TRANSFER_FAILED_EVENT: System.out.println("Failed to download, " + this.bytesRead + " bytes have been transferred"); break;