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


Java S3Object.setDataInputStream方法代码示例

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


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

示例1: put

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private void put(String key, InputStream in, long length, boolean storeMetadata)
    throws IOException {
  
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(in);
    object.setContentType("binary/octet-stream");
    object.setContentLength(length);
    if (storeMetadata) {
      object.addAllMetadata(METADATA);
    }
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:Jets3tFileSystemStore.java

示例2: saveImage

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private void saveImage(String filename, MultipartFile image) 
      throws ImageUploadException {
  
  try {
    AWSCredentials awsCredentials = 
      new AWSCredentials(s3AccessKey, s3SecretKey);      
    S3Service s3 = new RestS3Service(awsCredentials);
    
    S3Bucket imageBucket = s3.getBucket("spitterImages");
    S3Object imageObject = new S3Object(filename);
    
    imageObject.setDataInputStream(
            new ByteArrayInputStream(image.getBytes()));
    imageObject.setContentLength(image.getBytes().length);
    imageObject.setContentType("image/jpeg");
    
    AccessControlList acl = new AccessControlList();
    acl.setOwner(imageBucket.getOwner());
    acl.grantPermission(GroupGrantee.ALL_USERS, 
            Permission.PERMISSION_READ);
    imageObject.setAcl(acl);
    s3.putObject(imageBucket, imageObject); 
  } catch (Exception e) {
    throw new ImageUploadException("Unable to save image", e);
  }
}
 
开发者ID:liuxianqiang,项目名称:spring-in-action,代码行数:27,代码来源:SpitterController.java

示例3: storeEmptyFile

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeEmptyFile(String key) throws IOException {
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
    object.setContentType("binary/octet-stream");
    object.setContentLength(0);
    object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
    s3Service.putObject(bucket, object);
  } catch (ServiceException e) {
    handleException(e, key);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:Jets3tNativeFileSystemStore.java

示例4: storeFile

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeFile(String key, File file, byte[] md5Hash)
  throws IOException {

  if (multipartEnabled && file.length() >= multipartBlockSize) {
    storeLargeFile(key, file, md5Hash);
    return;
  }

  BufferedInputStream in = null;
  try {
    in = new BufferedInputStream(new FileInputStream(file));
    S3Object object = new S3Object(key);
    object.setDataInputStream(in);
    object.setContentType("binary/octet-stream");
    object.setContentLength(file.length());
    object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
    if (md5Hash != null) {
      object.setMd5Hash(md5Hash);
    }
    s3Service.putObject(bucket, object);
  } catch (ServiceException e) {
    handleException(e, key);
  } finally {
    IOUtils.closeStream(in);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:Jets3tNativeFileSystemStore.java

示例5: storeEmptyFile

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public void storeEmptyFile(String key) throws IOException {
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
    object.setContentType("binary/octet-stream");
    object.setContentLength(0);
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:15,代码来源:Jets3tNativeFileSystemStore.java

示例6: storeEmptyFile

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeEmptyFile(String key) throws IOException {
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
    object.setContentType("binary/octet-stream");
    object.setContentLength(0);
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    handleServiceException(e);
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:13,代码来源:Jets3tNativeFileSystemStore.java

示例7: storeFile

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeFile(String path, InputStream is, long size) throws IOException {
    path = stripLeadingSlash(path);
    S3Object fileObject = new S3Object(path);
    fileObject.setDataInputStream(is);
    if (size != -1) {
        fileObject.setContentLength(size);
    }
    try {
        service.putObject(bucketName, fileObject);
    } catch (S3ServiceException e) {
        throw new IOException(e);
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:15,代码来源:AmazonFileStorageService.java

示例8: storeEmptyFile

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeEmptyFile(String key) throws IOException {
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
    object.setContentType("binary/octet-stream");
    object.setContentLength(0);
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    handleS3ServiceException(e);
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:13,代码来源:Jets3tNativeFileSystemStore.java

示例9: splitFileIntoObjectsByMaxPartSize

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
/**
 * Split the given file into objects such that no object has a size greater than
 * the defined maximum part size. Each object uses a
 * {@link SegmentedRepeatableFileInputStream} input stream to manage its own
 * byte range within the underlying file.
 *
 * @param objectKey
 * the object key name to apply to all objects returned by this method.
 * @param file
 * a file to split into multiple parts.
 * @return
 * an ordered list of objects that can be uploaded as multipart parts to S3 to
 * re-constitute the given file in the service.
 *
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
public List<S3Object> splitFileIntoObjectsByMaxPartSize(String objectKey, File file)
    throws IOException, NoSuchAlgorithmException
{
    long fileLength = file.length();
    long partCount = fileLength / maxPartSize + (fileLength % maxPartSize > 0 ? 1 : 0);

    if (log.isDebugEnabled()) {
        log.debug("Splitting file " + file.getAbsolutePath() + " of "
            + fileLength + " bytes into " + partCount
            + " object parts with a maximum part size of " + maxPartSize);
    }

    ArrayList<S3Object> multipartPartList = new ArrayList<S3Object>();
    SegmentedRepeatableFileInputStream segFIS = null;

    for (long offset = 0; offset < partCount; offset++) {
        S3Object object = new S3Object(objectKey);
        if (offset < partCount - 1) {
            object.setContentLength(maxPartSize);
            segFIS = new SegmentedRepeatableFileInputStream(
                file, offset * maxPartSize, maxPartSize);
        } else {
            // Last part, may not be full size.
            long partLength = fileLength % maxPartSize;
            // Handle edge-case where last part is exactly the size of maxPartSize
            if (partLength == 0) {
                partLength = maxPartSize;
            }
            object.setContentLength(partLength);
            segFIS = new SegmentedRepeatableFileInputStream(
                file, offset * maxPartSize, partLength);
        }
        object.setContentLength(segFIS.available());
        object.setDataInputStream(segFIS);

        // Calculate part's MD5 hash and reset stream
        object.setMd5Hash(ServiceUtils.computeMD5Hash(segFIS));
        segFIS.reset();

        multipartPartList.add(object);
    }
    return multipartPartList;
}
 
开发者ID:guptavishal,项目名称:jets3t-aws-roles,代码行数:61,代码来源:MultipartUtils.java


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