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


Java StorageObject.getContentLength方法代码示例

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


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

示例1: retrieveMetadata

import org.jets3t.service.model.StorageObject; //导入方法依赖的package包/类
@Override
public FileMetadata retrieveMetadata(String key) throws IOException {
  StorageObject object = null;
  try {
    LOG.debug("Getting metadata for key: {} from bucket: {}",
        key, bucket.getName());
    object = s3Service.getObjectDetails(bucket.getName(), key);
    return new FileMetadata(key, object.getContentLength(),
        object.getLastModifiedDate().getTime());

  } catch (ServiceException e) {
    try {
      // process
      handleException(e, key);
      return null;
    } catch (FileNotFoundException fnfe) {
      // and downgrade missing files
      return null;
    }
  } finally {
    if (object != null) {
      object.closeDataInputStream();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:Jets3tNativeFileSystemStore.java

示例2: list

import org.jets3t.service.model.StorageObject; //导入方法依赖的package包/类
/**
 * list objects
 * @param prefix prefix
 * @param delimiter delimiter
 * @param maxListingLength max no. of entries
 * @param priorLastKey last key in any previous search
 * @return a list of matches
 * @throws IOException on any reported failure
 */

private PartialListing list(String prefix, String delimiter,
    int maxListingLength, String priorLastKey) throws IOException {
  try {
    if (!prefix.isEmpty() && !prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    StorageObjectsChunk chunk = s3Service.listObjectsChunked(bucket.getName(),
        prefix, delimiter, maxListingLength, priorLastKey);
    
    FileMetadata[] fileMetadata =
      new FileMetadata[chunk.getObjects().length];
    for (int i = 0; i < fileMetadata.length; i++) {
      StorageObject object = chunk.getObjects()[i];
      fileMetadata[i] = new FileMetadata(object.getKey(),
          object.getContentLength(), object.getLastModifiedDate().getTime());
    }
    return new PartialListing(chunk.getPriorLastKey(), fileMetadata,
        chunk.getCommonPrefixes());
  } catch (ServiceException e) {
    handleException(e, prefix);
    return null; // never returned - keep compiler happy
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:34,代码来源:Jets3tNativeFileSystemStore.java

示例3: retrieveMetadata

import org.jets3t.service.model.StorageObject; //导入方法依赖的package包/类
@Override
public FileMetadata retrieveMetadata(String key) throws IOException {
  StorageObject object = null;
  try {
    if(LOG.isDebugEnabled()) {
      LOG.debug("Getting metadata for key: " + key + " from bucket:" + bucket.getName());
    }
    object = s3Service.getObjectDetails(bucket.getName(), key);
    return new FileMetadata(key, object.getContentLength(),
        object.getLastModifiedDate().getTime());

  } catch (ServiceException e) {
    // Following is brittle. Is there a better way?
    if ("NoSuchKey".equals(e.getErrorCode())) {
      return null; //return null if key not found
    }
    handleServiceException(e);
    return null; //never returned - keep compiler happy
  } finally {
    if (object != null) {
      object.closeDataInputStream();
    }
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:25,代码来源:Jets3tNativeFileSystemStore.java

示例4: downloadThrows

import org.jets3t.service.model.StorageObject; //导入方法依赖的package包/类
private void downloadThrows(final S3Artifact s3Artifact, final Path downloadTo) throws Exception {
  log.info("Downloading {}", s3Artifact);

  Jets3tProperties jets3tProperties = Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME);
  jets3tProperties.setProperty("httpclient.socket-timeout-ms", Long.toString(configuration.getS3ChunkDownloadTimeoutMillis()));

  final S3Service s3 = new RestS3Service(getCredentialsForBucket(s3Artifact.getS3Bucket()), null, null, jets3tProperties);

  long length = 0;

  if (s3Artifact.getFilesize().isPresent()) {
    length = s3Artifact.getFilesize().get();
  } else {
    StorageObject details = s3.getObjectDetails(s3Artifact.getS3Bucket(), s3Artifact.getS3ObjectKey());

    Preconditions.checkNotNull(details, "Couldn't find object at %s/%s", s3Artifact.getS3Bucket(), s3Artifact.getS3ObjectKey());

    length = details.getContentLength();
  }

  int numChunks = (int) (length / configuration.getS3ChunkSize());

  if (length % configuration.getS3ChunkSize() > 0) {
    numChunks++;
  }

  final long chunkSize = length / numChunks + (length % numChunks);

  log.info("Downloading {}/{} in {} chunks of {} bytes to {}", s3Artifact.getS3Bucket(), s3Artifact.getS3ObjectKey(), numChunks, chunkSize, downloadTo);

  final ExecutorService chunkExecutorService = Executors.newFixedThreadPool(numChunks, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("S3ArtifactDownloaderChunkThread-%d").build());
  final List<Future<Path>> futures = Lists.newArrayListWithCapacity(numChunks);

  for (int chunk = 0; chunk < numChunks; chunk++) {
    futures.add(chunkExecutorService.submit(new S3ArtifactChunkDownloader(configuration, log, s3, s3Artifact, downloadTo, chunk, chunkSize, length, exceptionNotifier)));
  }

  long remainingMillis = configuration.getS3DownloadTimeoutMillis();
  boolean failed = false;

  for (int chunk = 0; chunk < numChunks; chunk++) {
    final Future<Path> future = futures.get(chunk);

    if (failed) {
      future.cancel(true);
      continue;
    }

    final long start = System.currentTimeMillis();

    if (!handleChunk(s3Artifact, future, downloadTo, chunk, start, remainingMillis)) {
      failed = true;
    }

    remainingMillis -= (System.currentTimeMillis() - start);
  }

  chunkExecutorService.shutdownNow();

  Preconditions.checkState(!failed, "Downloading %s/%s failed", s3Artifact.getS3Bucket(), s3Artifact.getS3ObjectKey());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:62,代码来源:S3ArtifactDownloader.java


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