@Override protected InputStream createStream(long startPos, long endPos) throws IOException { GetObjectRequest req = new GetObjectRequest(mBucketName, mKey); // COS returns entire object if we read past the end req.setRange(startPos, endPos < mContentLength ? endPos - 1 : mContentLength - 1); COSObject object = mCosClient.getObject(req); return new BufferedInputStream(object.getObjectContent()); } }
/** * <p> * Sets the optional inclusive byte range within the desired object that will be downloaded by * this request. Returns this {@link GetObjectRequest}, enabling additional method calls to be * chained together. * </p> * <p> * The first byte in an object has position 0; as an example, the first ten bytes of an object * can be downloaded by specifying a range of 0 to 9. * </p> * <p> * If no byte range is specified, this request downloads the entire object from Qcloud COS. * </p> * * @param start The start of the inclusive byte range to download. * @param end The end of the inclusive byte range to download. * * @return This {@link GetObjectRequest}, enabling additional method calls to be chained * together. * * @see GetObjectRequest#getRange() * @see GetObjectRequest#setRange(long, long) */ public GetObjectRequest withRange(long start, long end) { setRange(start, end); return this; }
/** * <p> * Sets the optional inclusive byte range within the desired object that will be downloaded by * this request. Returns this {@link GetObjectRequest}, enabling additional method calls to be * chained together. * </p> * <p> * The first byte in an object has position 0; as an example, the first ten bytes of an object * can be downloaded by specifying a range of 0 to 9. * </p> * <p> * If no byte range is specified, this request downloads the entire object from Qcloud COS. * </p> * * @param start The start of the inclusive byte range to download. * @param end The end of the inclusive byte range to download. * * @return This {@link GetObjectRequest}, enabling additional method calls to be chained * together. * * @see GetObjectRequest#getRange() * @see GetObjectRequest#setRange(long, long) */ public GetObjectRequest withRange(long start, long end) { setRange(start, end); return this; }
+ Arrays.toString(new long[] {startingByte, lastByte}) + " for file " + dstfile); req.setRange(startingByte, lastByte); totalBytesToDownload = lastByte - startingByte + 1; } finally {
+ Arrays.toString(new long[] {startingByte, lastByte}) + " for file " + dstfile); req.setRange(startingByte, lastByte); totalBytesToDownload = lastByte - startingByte + 1; } finally {
long[] adjustedCryptoRange = getAdjustedCryptoRange(desiredRange); if (adjustedCryptoRange != null) req.setRange(adjustedCryptoRange[0], adjustedCryptoRange[1]);
long[] adjustedCryptoRange = getAdjustedCryptoRange(desiredRange); if (adjustedCryptoRange != null) req.setRange(adjustedCryptoRange[0], adjustedCryptoRange[1]);
/** * Resumes an download operation. This download operation uses the same configuration as the * original download. Any data already fetched will be skipped, and only the remaining data is * retrieved from Qcloud COS. * * @param persistableDownload the download to resume. * @return A new <code>Download</code> object to use to check the state of the download, listen * for progress notifications, and otherwise manage the download. * * @throws CosClientException If any errors are encountered in the client while making the * request or handling the response. * @throws CosServiceException If any errors occurred in Qcloud COS while processing the * request. */ public Download resumeDownload(PersistableDownload persistableDownload) { assertParameterNotNull(persistableDownload, "PausedDownload is mandatory to resume a download."); GetObjectRequest request = new GetObjectRequest(persistableDownload.getBucketName(), persistableDownload.getKey(), persistableDownload.getVersionId()); if (persistableDownload.getRange() != null && persistableDownload.getRange().length == 2) { long[] range = persistableDownload.getRange(); request.setRange(range[0], range[1]); } request.setResponseHeaders(persistableDownload.getResponseHeaders()); return doDownload(request, new File(persistableDownload.getFile()), null, null, APPEND_MODE); }
/** * Resumes an download operation. This download operation uses the same configuration as the * original download. Any data already fetched will be skipped, and only the remaining data is * retrieved from Qcloud COS. * * @param persistableDownload the download to resume. * @return A new <code>Download</code> object to use to check the state of the download, listen * for progress notifications, and otherwise manage the download. * * @throws CosClientException If any errors are encountered in the client while making the * request or handling the response. * @throws CosServiceException If any errors occurred in Qcloud COS while processing the * request. */ public Download resumeDownload(PersistableDownload persistableDownload) { assertParameterNotNull(persistableDownload, "PausedDownload is mandatory to resume a download."); GetObjectRequest request = new GetObjectRequest(persistableDownload.getBucketName(), persistableDownload.getKey(), persistableDownload.getVersionId()); if (persistableDownload.getRange() != null && persistableDownload.getRange().length == 2) { long[] range = persistableDownload.getRange(); request.setRange(range[0], range[1]); } request.setResponseHeaders(persistableDownload.getResponseHeaders()); return doDownload(request, new File(persistableDownload.getFile()), null, null, APPEND_MODE); }
fileLength = file.length(); startingByte = startingByte + fileLength; getObjectRequest.setRange(startingByte, lastByte); transferProgress.updateProgress(Math.min(fileLength, totalBytesToDownload)); totalBytesToDownload = lastByte - startingByte + 1;
fileLength = file.length(); startingByte = startingByte + fileLength; getObjectRequest.setRange(startingByte, lastByte); transferProgress.updateProgress(Math.min(fileLength, totalBytesToDownload)); totalBytesToDownload = lastByte - startingByte + 1;