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


Java S3Object.setContentType方法代码示例

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


在下文中一共展示了S3Object.setContentType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: readFolderContents

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private void readFolderContents(File folder)
		throws NoSuchAlgorithmException, IOException, S3ServiceException {
	Iterator filesinFolder = fileUtils.iterateFiles(folder, null, true);
	while (filesinFolder.hasNext()) {
		Object file = filesinFolder.next();
		Logger.debug("File: " + file);
		String key = "testfilnamekey";
		if (folder.isDirectory()) {
			S3Object s3Obj = new S3Object(bucket, (File) file);
			s3Obj.setKey(key);
			s3Obj.setContentType(Mimetypes.getInstance().getMimetype(
					s3Obj.getKey()));
			s3Objs.add(s3Obj);
		} else {
			Logger.warn("S3FS.readFolderContents() File: "
					+ folder.getName() + " is not a folder.");
		}
	}
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:20,代码来源:S3FS.java

示例5: getDetails

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
/**
 * Add default metadata
 */
protected S3Object getDetails(final Path file, final TransferStatus status) {
    final S3Object object = new S3Object(containerService.getKey(file));
    final String mime = status.getMime();
    if(StringUtils.isNotBlank(mime)) {
        object.setContentType(mime);
    }
    final Checksum checksum = status.getChecksum();
    if(Checksum.NONE != checksum) {
        switch(checksum.algorithm) {
            case md5:
                object.setMd5Hash(ServiceUtils.fromHex(checksum.hash));
                break;
            case sha256:
                object.addMetadata("x-amz-content-sha256", checksum.hash);
                break;
        }
    }
    if(StringUtils.isNotBlank(status.getStorageClass())) {
        if(!S3Object.STORAGE_CLASS_STANDARD.equals(status.getStorageClass())) {
            // The default setting is STANDARD.
            object.setStorageClass(status.getStorageClass());
        }
    }
    final Encryption.Algorithm encryption = status.getEncryption();
    object.setServerSideEncryptionAlgorithm(encryption.algorithm);
    // If the x-amz-server-side-encryption is present and has the value of aws:kms, this header specifies the ID of the
    // AWS Key Management Service (KMS) master encryption key that was used for the object.
    object.setServerSideEncryptionKmsKeyId(encryption.key);
    for(Map.Entry<String, String> m : status.getMetadata().entrySet()) {
        object.addMetadata(m.getKey(), m.getValue());
    }
    return object;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:37,代码来源:S3WriteFeature.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);
    object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
    s3Service.putObject(bucket, object);
  } catch (ServiceException e) {
    handleException(e, key);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:Jets3tNativeFileSystemStore.java

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

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

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

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

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

示例12: upload

import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public static void upload(String sessionId, String name) {
	logger.debug("Upload - session id: {} name: {}", sessionId, name);
	try {
		// find the file
		StringBuilder sb = new StringBuilder(recordPath);
		sb.append(sessionId);
		sb.append('/');
		sb.append(name);
		sb.append(".flv");
		String filePath = sb.toString();
		logger.debug("File path: {}", filePath);
		File file = new File(filePath);
		if (file.exists()) {
			S3Service s3Service = new RestS3Service(awsCredentials);
			S3Bucket bucket = s3Service.createBucket(bucketName);
			S3Object sob = new S3Object(sessionId + "/" + name + ".flv");
			// force bucket name
			sob.setBucketName(bucketName);
			// point at file
			sob.setDataInputFile(file);
			// set type
			sob.setContentType("video/x-flv");
			// set auth / acl
			sob.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);				
			logger.debug("Pre-upload: {}", sob);
			sob = s3Service.putObject(bucket, sob);
			logger.debug("Post-upload: {}", sob);						
		} else {
			logger.warn("File was not found");
		}
		file = null;
	} catch (S3ServiceException e) {
		logger.error("Error during upload", e);
	}		
}
 
开发者ID:Red5,项目名称:red5-examples,代码行数:36,代码来源:S3FilenameGenerator.java

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

示例14: 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.setContentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。