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


Java S3Object.setContentLength方法代码示例

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


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

示例1: storeLargeFile

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public void storeLargeFile(String key, File file, byte[] md5Hash)
    throws IOException {
  S3Object object = new S3Object(key);
  object.setDataInputFile(file);
  object.setContentType("binary/octet-stream");
  object.setContentLength(file.length());
  object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
  if (md5Hash != null) {
    object.setMd5Hash(md5Hash);
  }

  List<StorageObject> objectsToUploadAsMultipart =
      new ArrayList<StorageObject>();
  objectsToUploadAsMultipart.add(object);
  MultipartUtils mpUtils = new MultipartUtils(multipartBlockSize);

  try {
    mpUtils.uploadObjects(bucket.getName(), s3Service,
                          objectsToUploadAsMultipart, null);
  } catch (Exception e) {
    handleException(e, key);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:Jets3tNativeFileSystemStore.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: contentStreamClosed

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public void contentStreamClosed() throws ContentIOException {
	if(LOG.isDebugEnabled()){
	  LOG.debug("S3StreamListener.contentStreamClosed(): Retrieving Temp File Stream");
	}
	try {
		final File file = writer.getTempFile();
		final long size = file.length();
		writer.setSize(size);
		final String url = writer.getNodeUrl();
		final S3Object object = new S3Object(url);
		object.setDataInputFile(file);
		object.setContentLength(size);
		object.setContentType("application/octetstream");

		try {
			s3Service.putObject(bucket, object);
		} catch (S3ServiceException s3ServExcp) {
			if(LOG.isErrorEnabled()){
				LOG.error("S3StreamListener Failed to Upload File: "+ s3ServExcp);
			}
		} finally {
			//clean data input stream
			object.closeDataInputStream();
		} 
	} catch (Exception excp) {
		if(LOG.isErrorEnabled()){
			LOG.error("S3StreamListener Failed: "+ excp);
		}
	}
}
 
开发者ID:abhinavmishra14,项目名称:alfresco-amazon-s3-content-store-integration,代码行数:31,代码来源:S3StreamListener.java

示例10: 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

示例11: uploadFile

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public static void uploadFile(final File file, final String fileName, final ContentTypeEnum contentType, final boolean rewrite) {
	try {
		
		s3Service = new RestS3Service(AWSCREDENTIALS);
		AccessControlList bucketAcl = s3Service.getBucketAcl("pubanywhere");
		bucketAcl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ);
		pubanywhere = s3Service.getBucket("pubanywhere");
		
		if (pubanywhere != null) {
			S3Object object = new S3Object(pubanywhere, file);
			object.setContentLength(file.length());
			object.setContentType(contentType.getDescricao());
			object.setName(fileName);
			object.setAcl(bucketAcl);
			
			if (rewrite) {
				s3Service.putObject(pubanywhere, object);
			} else {
				if (!isFileOnAmazon(fileName)) {
					s3Service.putObject(pubanywhere, object);
				}
			}
			
			log.info("Uploading file: " + fileName + " on amazon");
		}
		
	} catch (Exception e) {
		log.error("Error uploading file: " + fileName, e.getMessage());
	}
}
 
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:31,代码来源:AmazonService.java

示例12: 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

示例13: createObjectForUpload

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
/**
 * Prepares a file for upload to a named object in S3, potentially transforming it if
 * zipping or encryption is requested.
 * <p>
 * The file will have the following metadata items added:
 * <ul>
 * <li>{@link Constants#METADATA_JETS3T_LOCAL_FILE_DATE}: The local file's last modified date
 *     in ISO 8601 format</li>
 * <li><tt>Content-Type</tt> : A content type guessed from the file's extension, or
 *     {@link Mimetypes#MIMETYPE_BINARY_OCTET_STREAM} if the file is a directory</li>
 * <li><tt>Content-Length</tt> : The size of the file</li>
 * <li><tt>MD5-Hash</tt> : An MD5 hash of the file's data</li>
 * <li>{@link StorageObject#METADATA_HEADER_ORIGINAL_HASH_MD5}: An MD5 hash of the
 *     original file's data (added if gzipping or encryption is applied)</li>
 * </ul>
 *
 * @param objectKey
 * the object key name to use in S3
 * @param dataFile
 * the file to prepare for upload.
 * @param encryptionUtil
 * if this variable is null no encryption will be applied, otherwise the provided
 * encryption utility object will be used to encrypt the file's data.
 * @param gzipFile
 * if true the file will be Gzipped.
 * @param progressWatcher
 * watcher to monitor progress of file transformation and hash generation.
 *
 * @return
 * an S3Object representing the file, or a transformed copy of the file, complete with
 * all JetS3t-specific metadata items set and ready for upload to S3.
 *
 * @throws Exception
 * exceptions could include IO failures, gzipping and encryption failures.
 */
public static S3Object createObjectForUpload(String objectKey, File dataFile,
    EncryptionUtil encryptionUtil, boolean gzipFile, BytesProgressWatcher progressWatcher)
    throws Exception
{
    S3Object s3Object = new S3Object(objectKey);

    // Set object explicitly to private access by default.
    s3Object.setAcl(AccessControlList.REST_CANNED_PRIVATE);

    s3Object.addMetadata(Constants.METADATA_JETS3T_LOCAL_FILE_DATE,
        ServiceUtils.formatIso8601Date(new Date(dataFile.lastModified())));

    if (dataFile.isDirectory()) {
        s3Object.setContentLength(0);
        s3Object.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM);
    } else {
        s3Object.setContentType(Mimetypes.getInstance().getMimetype(dataFile));
        File uploadFile = transformUploadFile(dataFile, s3Object, encryptionUtil,
            gzipFile, progressWatcher);
        s3Object.setContentLength(uploadFile.length());
        s3Object.setDataInputFile(uploadFile);

        // Compute the upload file's MD5 hash.
        InputStream inputStream = new BufferedInputStream(new FileInputStream(uploadFile));
        if (progressWatcher != null) {
            inputStream = new ProgressMonitoredInputStream(inputStream, progressWatcher);
        }
        s3Object.setMd5Hash(ServiceUtils.computeMD5Hash(inputStream));

        if (!uploadFile.equals(dataFile)) {
            // Compute the MD5 hash of the *original* file, if upload file has been altered
            // through encryption or gzipping.
            inputStream = new BufferedInputStream(new FileInputStream(dataFile));
            if (progressWatcher != null) {
                inputStream = new ProgressMonitoredInputStream(inputStream, progressWatcher);
            }

            s3Object.addMetadata(
                S3Object.METADATA_HEADER_ORIGINAL_HASH_MD5,
                ServiceUtils.toBase64(ServiceUtils.computeMD5Hash(inputStream)));
        }
    }
    return s3Object;
}
 
开发者ID:guptavishal,项目名称:jets3t-aws-roles,代码行数:80,代码来源:ObjectUtils.java


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