当前位置: 首页>>代码示例>>Java>>正文


Java GetObjectRequest.setRange方法代码示例

本文整理汇总了Java中com.amazonaws.services.s3.model.GetObjectRequest.setRange方法的典型用法代码示例。如果您正苦于以下问题:Java GetObjectRequest.setRange方法的具体用法?Java GetObjectRequest.setRange怎么用?Java GetObjectRequest.setRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.s3.model.GetObjectRequest的用法示例。


在下文中一共展示了GetObjectRequest.setRange方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGetS3Object

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
private S3Object doGetS3Object(URI uri, boolean isLightWeight) {
    S3RegionalResource s3RegionalResource = new S3RegionalResource(uri);
    String bucketName = s3RegionalResource.getBucketName();
    String s3BucketKey = s3RegionalResource.getKey();
    configureClient(s3RegionalResource);

    GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, s3BucketKey);
    if (isLightWeight) {
        //Skip content download
        getObjectRequest.setRange(0, 0);
    }

    try {
        return amazonS3Client.getObject(getObjectRequest);
    } catch (AmazonServiceException e) {
        String errorCode = e.getErrorCode();
        if (null != errorCode && errorCode.equalsIgnoreCase("NoSuchKey")) {
            return null;
        }
        throw ResourceExceptions.getFailed(uri, e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:23,代码来源:S3Client.java

示例2: resumeDownload

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
/**
 * 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 Amazon S3.
 *
 * @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 AmazonClientException
 *             If any errors are encountered in the client while making the
 *             request or handling the response.
 * @throws AmazonServiceException
 *             If any errors occurred in Amazon S3 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.setRequesterPays(persistableDownload.isRequesterPays());
    request.setResponseHeaders(persistableDownload.getResponseHeaders());

    return doDownload(request, new File(persistableDownload.getFile()), null, null,
            APPEND_MODE, 0,
            persistableDownload.getLastFullyDownloadedPartNumber(),
            persistableDownload.getlastModifiedTime());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:38,代码来源:TransferManager.java

示例3: readData

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
/**
 * S3 block read would be achieved through the AmazonS3 client. Following
 * are the steps to achieve: (1) Create the objectRequest from bucketName
 * and filePath. (2) Set the range to the above created objectRequest. (3)
 * Get the object portion through AmazonS3 client API. (4) Get the object
 * content from the above object portion.
 *
 * @param bytesFromCurrentOffset
 *          bytes read till now from current offset
 * @param bytesToFetch
 *          the number of bytes to be fetched
 * @return the number of bytes read, -1 if 0 bytes read
 * @throws IOException
 */

@Override
protected int readData(final long bytesFromCurrentOffset, final int bytesToFetch) throws IOException
{
  GetObjectRequest rangeObjectRequest = new GetObjectRequest(s3Params.bucketName, s3Params.filePath);
  rangeObjectRequest.setRange(offset + bytesFromCurrentOffset, offset + bytesFromCurrentOffset + bytesToFetch - 1);
  S3Object objectPortion = s3Params.s3Client.getObject(rangeObjectRequest);
  S3ObjectInputStream wrappedStream = objectPortion.getObjectContent();
  buffer = ByteStreams.toByteArray(wrappedStream);
  wrappedStream.close();
  int bufferLength = buffer.length;
  if (bufferLength <= 0) {
    return -1;
  }
  return bufferLength;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:31,代码来源:S3RecordReader.java

示例4: readEntity

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
/**
 * S3 block read would be achieved through the AmazonS3 client. Following are the steps to achieve:
 * (1) Create the objectRequest from bucketName and filePath.
 * (2) Set the range to the above created objectRequest.
 * (3) Get the object portion through AmazonS3 client API.
 * (4) Get the object content from the above object portion.
 * @return the block entity
 * @throws IOException
 */
@Override
protected Entity readEntity() throws IOException
{
  entity.clear();
  GetObjectRequest rangeObjectRequest = new GetObjectRequest(
      bucketName, filePath);
  rangeObjectRequest.setRange(offset, blockMetadata.getLength() - 1);
  S3Object objectPortion = s3Client.getObject(rangeObjectRequest);
  S3ObjectInputStream wrappedStream = objectPortion.getObjectContent();
  byte[] record = ByteStreams.toByteArray(wrappedStream);
  entity.setUsedBytes(record.length);
  entity.setRecord(record);
  wrappedStream.close();
  return entity;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:25,代码来源:S3BlockReader.java

示例5: reopen

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
private synchronized void reopen(long pos) throws IOException {

    if (wrappedStream != null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Aborting old stream to open at pos " + pos);
      }
      wrappedStream.abort();
    }

    if (pos < 0) {
      throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK
          +" " + pos);
    }

    if (contentLength > 0 && pos > contentLength-1) {
      throw new EOFException(
          FSExceptionMessages.CANNOT_SEEK_PAST_EOF
          + " " + pos);
    }

    LOG.debug("Actually opening file " + key + " at pos " + pos);

    GetObjectRequest request = new GetObjectRequest(bucket, key);
    request.setRange(pos, contentLength-1);

    wrappedStream = client.getObject(request).getObjectContent();

    if (wrappedStream == null) {
      throw new IOException("Null IO stream");
    }

    this.pos = pos;
  }
 
开发者ID:naver,项目名称:hadoop,代码行数:34,代码来源:S3AInputStream.java

示例6: adjustRequest

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
/**
 * This method is called only if it is a resumed download.
 *
 * Adjust the range of the get request, and the expected (ie current) file
 * length of the destination file to append to.
 */
private void adjustRequest(GetObjectRequest req) {
    long[] range = req.getRange();
    long lastByte = range[1];
    long totalBytesToDownload = lastByte - this.origStartingByte + 1;

    if (dstfile.exists()) {
        if (!FileLocks.lock(dstfile)) {
            throw new FileLockException("Fail to lock " + dstfile
                    + " for range adjustment");
        }
        try {
            expectedFileLength = dstfile.length();
            long startingByte = this.origStartingByte + expectedFileLength;
            LOG.info("Adjusting request range from " + Arrays.toString(range)
                    + " to "
                    + Arrays.toString(new long[] { startingByte, lastByte })
                    + " for file " + dstfile);
            req.setRange(startingByte, lastByte);
            totalBytesToDownload = lastByte - startingByte + 1;
        } finally {
            FileLocks.unlock(dstfile);
        }
    }

    if (totalBytesToDownload < 0) {
        throw new IllegalArgumentException(
            "Unable to determine the range for download operation. lastByte="
                    + lastByte + ", origStartingByte=" + origStartingByte
                    + ", expectedFileLength=" + expectedFileLength
                    + ", totalBytesToDownload=" + totalBytesToDownload);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:39,代码来源:DownloadCallable.java

示例7: getObjectSecurely

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
@Override
public S3Object getObjectSecurely(GetObjectRequest req) {
    appendUserAgent(req, USER_AGENT);
    // Adjust the crypto range to retrieve all of the cipher blocks needed to contain the user's desired
    // range of bytes.
    long[] desiredRange = req.getRange();
    if (isStrict() && (desiredRange  != null || req.getPartNumber() != null))
        throw new SecurityException("Range get and getting a part are not allowed in strict crypto mode");
    long[] adjustedCryptoRange = getAdjustedCryptoRange(desiredRange);
    if (adjustedCryptoRange != null)
        req.setRange(adjustedCryptoRange[0], adjustedCryptoRange[1]);
    // Get the object from S3
    S3Object retrieved = s3.getObject(req);
    // If the caller has specified constraints, it's possible that super.getObject(...)
    // would return null, so we simply return null as well.
    if (retrieved == null)
        return null;
    String suffix = null;
    if (req instanceof EncryptedGetObjectRequest) {
        EncryptedGetObjectRequest ereq = (EncryptedGetObjectRequest)req;
        suffix = ereq.getInstructionFileSuffix();
    }
    try {
        return suffix == null || suffix.trim().isEmpty()
         ? decipher(req, desiredRange, adjustedCryptoRange, retrieved)
         : decipherWithInstFileSuffix(req,
                 desiredRange, adjustedCryptoRange, retrieved,
                 suffix)
         ;
    } catch (RuntimeException ex) {
        // If we're unable to set up the decryption, make sure we close the
        // HTTP connection
        closeQuietly(retrieved, log);
        throw ex;
    } catch (Error error) {
        closeQuietly(retrieved, log);
        throw error;
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:40,代码来源:S3CryptoModuleAE.java

示例8: computeSumForChunk

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
@Override
public int computeSumForChunk(String bucketName, String filename, int chunkNumber, int chunkSize) throws IOException {
    int sum = 0;
    int from = chunkNumber * chunkSize;
    int to = from + chunkSize;

    int offset = chunkNumber * chunkSize * ROW_SIZE;
    int bytesToRead = chunkSize * ROW_SIZE;

    // Create a request to download content for computing the sum for this chunk
    GetObjectRequest getRequest = new GetObjectRequest(bucketName, filename);
    getRequest.setRange(offset, offset + bytesToRead - 1);

    // Download content
    S3Object obj = storage.getObject(getRequest);
    InputStream inputStream = obj.getObjectContent();
    InputStreamReader inputStreamReader = null;
    BufferedReader reader = null;
    try {
        String line = null;
        inputStreamReader = new InputStreamReader(inputStream);
        reader = new BufferedReader(inputStreamReader);

        // Compute sum for downloaded content
        while ((line = reader.readLine()) != null) {
            sum += Integer.parseInt(line);
        }
    }
    finally {
        if (reader != null)
            reader.close();
        if (inputStreamReader != null)
            inputStreamReader.close();
        if (inputStream != null)
            inputStream.close();
    }

    System.out.printf("Sum from '%d' to '%d' is: '%d'\n", from + 1, to, sum);
    return sum;
}
 
开发者ID:pedropaulovc,项目名称:aws-flow-maven-eclipse-samples,代码行数:41,代码来源:AverageCalculatorActivitiesImpl.java

示例9: getInputStream

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
@Override
public InputStream getInputStream() throws IOException {
    LOG.info(String.format("get s3 file by client %s: bucket=%s, key=%s",
            client, bucket, key));
    GetObjectRequest req = new GetObjectRequest(bucket, key);
    req.setRange(0, size);
    S3Object object = client.getObject(req);

    if (object != null) {
        return object.getObjectContent();
    } else {
        throw new IOException("s3 file is null.");
    }
}
 
开发者ID:treasure-data,项目名称:td-import-java,代码行数:15,代码来源:S3Source.java

示例10: read

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
@Override
public long read(String path, ByteBuffer dst, long position) throws IOException {
  log.debug("Read file at {}/{}", bucket, path);

  GetObjectRequest request = new GetObjectRequest(bucket, path);
  request.setRange(position, position + dst.remaining() - 1);
  try (S3Object s3Object = s3Client.getObject(request)) {
    try (S3ObjectInputStream is = s3Object.getObjectContent()) {
      try (ByteBufferOutputStream os = new ByteBufferOutputStream(dst)) {
        return ByteStreams.copy(is, os);
      }
    }
  }
}
 
开发者ID:justinsb,项目名称:cloudata,代码行数:15,代码来源:S3ObjectStore.java

示例11: initializeDownload

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
@Override
public MultiPartDownload initializeDownload(File file, RemoteFile remoteFile) throws IOException {

    long start = 0;
    long end = Constants.CHUNK_DOWNLOAD_SIZE - 1;
    String child = remoteFile.getPath();

    GetObjectRequest rangeObjectRequest = new GetObjectRequest(
            getBucketName(), child);

    rangeObjectRequest.setRange(start, end);

    S3Object obj = s3.getObject(rangeObjectRequest);

    BufferedInputStream bis = new BufferedInputStream(obj.getObjectContent());

    writeStreamToFile(bis, file);

    MultiPartDownload mpd = new MultiPartDownload(file, remoteFile, end);

    return mpd;
}
 
开发者ID:modcs,项目名称:caboclo,代码行数:23,代码来源:AmazonClient.java

示例12: loadFromTo

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
/**
 * A method that creates an InputStream on a specific range of the file.
 * InputStream classes wrapping order can be reversed.
 *
 * @param obj    target file URI
 * @param offset range start position
 * @param end    range end position
 * @return an InputStream object on the specific range of the file.
 */
public InputStream loadFromTo(AmazonS3URI obj, long offset, long end) {
    GetObjectRequest rangeObjectRequest = new GetObjectRequest(obj.getBucket(), obj.getKey());
    rangeObjectRequest.setRange(offset, end);
    S3Object s3Object = client.getAws().getObject(rangeObjectRequest);
    PerformanceMonitor.logRequest();
    S3ObjectInputStream objectStream = s3Object.getObjectContent();
    return new MonitoredInputStream(new BufferedInputStream(objectStream));
}
 
开发者ID:epam,项目名称:htsjdk-s3-plugin,代码行数:18,代码来源:S3InputStreamFactory.java

示例13: getNextPart

import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
@Override
public void getNextPart(MultiPartDownload mpd) throws IOException {
    RemoteFile remoteFile = mpd.getRemotePath();
    File file = mpd.getFile();

    long start = mpd.getOffset() + 1;
    long end = mpd.getOffset() + Constants.CHUNK_DOWNLOAD_SIZE - 1;

    boolean finished = false;

    if (end > mpd.getRemotePath().getSize()) {
        end = mpd.getRemotePath().getSize();

        finished = true;
    }

    String child = remoteFile.getPath();

    GetObjectRequest rangeObjectRequest = new GetObjectRequest(
            getBucketName(), child);

    rangeObjectRequest.setRange(start, end);

    S3Object obj = s3.getObject(rangeObjectRequest);

    BufferedInputStream bis = new BufferedInputStream(obj.getObjectContent());

    ByteArrayOutputStream baos = new ByteArrayOutputStream(Constants.CHUNK_DOWNLOAD_SIZE);

    writeStreamToByteStream(bis, baos);

    appendFile(file, baos.toByteArray());

    mpd.setOffset(end);

    mpd.setFinished(finished);

}
 
开发者ID:modcs,项目名称:caboclo,代码行数:39,代码来源:AmazonClient.java


注:本文中的com.amazonaws.services.s3.model.GetObjectRequest.setRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。