本文整理汇总了Java中org.jets3t.service.model.S3Object.setDataInputFile方法的典型用法代码示例。如果您正苦于以下问题:Java S3Object.setDataInputFile方法的具体用法?Java S3Object.setDataInputFile怎么用?Java S3Object.setDataInputFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jets3t.service.model.S3Object
的用法示例。
在下文中一共展示了S3Object.setDataInputFile方法的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);
}
}
示例2: testBasicRename
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testBasicRename()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
S3HdfsPath s3HdfsPath2 = testUtil.setUpS3HdfsPath("folder", "file2");
// Get the object
S3Bucket bucket = new S3Bucket(s3HdfsPath1.getBucketName());
// Put new object
File file = testUtil.getFile(BIG_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
S3Object object2 = new S3Object(s3HdfsPath2.getObjectName());
object1.setDataInputFile(file);
s3Service.putObject(bucket.getName(), object1);
// Rename is done as a PUT, COPY, and DELETE
s3Service.renameObject(bucket.getName(), object1.getKey(), object2);
// Compare rename with original
testUtil.compareS3ObjectWithHdfsFile(new FileInputStream(file),
new Path(s3HdfsPath2.getFullHdfsObjPath()));
}
示例3: 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
示例4: testDeleteVersion
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testDeleteVersion()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
// Enable versioning
S3Bucket retBucket =
s3Service.createBucket(new S3Bucket(s3HdfsPath1.getBucketName()));
s3Service.enableBucketVersioning(retBucket.getName());
// Put new object
File file1 = testUtil.getFile(BIG_SIZE);
File file2 = testUtil.getFile(SMALL_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
object1.setDataInputFile(file1);
S3Object object2 = new S3Object(s3HdfsPath1.getObjectName());
object2.setDataInputFile(file2);
S3Object ret1 = s3Service.putObject(s3HdfsPath1.getBucketName(), object1);
s3Service.putObject(s3HdfsPath1.getBucketName(), object2);
FileStatus[] fs =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(2, fs.length);
s3Service.deleteVersionedObject(ret1.getVersionId(),
s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
FileStatus[] fs2 =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(1, fs2.length);
}
示例5: testBigCopy
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testBigCopy()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
S3HdfsPath s3HdfsPath2 = testUtil.setUpS3HdfsPath("folder", "file2");
// Get the object
S3Bucket bucket = new S3Bucket(s3HdfsPath1.getBucketName());
// Put new object
File file = testUtil.getFile(BIG_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
object1.setDataInputFile(file);
s3Service.putObject(bucket.getName(), object1);
// Prepare copy object
S3Object object2 = new S3Object(s3HdfsPath2.getObjectName(), "");
s3Service.copyObject(bucket.getName(), object1.getKey(),
bucket.getName(), object2, false);
FileStatus[] fs2 =
hdfs.listStatus(new Path(s3HdfsPath2.getFullHdfsObjPath()));
assertEquals(1, fs2.length);
assertTrue(fs2[0].getPath().getName().equals(OBJECT_FILE_NAME));
assertTrue(!fs2[0].isDirectory());
assertEquals(BIG_SIZE, fs2[0].getLen());
testUtil.compareS3ObjectWithHdfsFile(new FileInputStream(file),
new Path(s3HdfsPath2.getFullHdfsObjPath()));
}
示例6: 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);
}
}
示例7: 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;
}
示例8: testBasicVersionedPut
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testBasicVersionedPut()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
// Enable versioning
S3Bucket retBucket =
s3Service.createBucket(new S3Bucket(s3HdfsPath1.getBucketName()));
s3Service.enableBucketVersioning(retBucket.getName());
// Put new object
File file1 = testUtil.getFile(BIG_SIZE);
File file2 = testUtil.getFile(SMALL_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
object1.setDataInputFile(file1);
S3Object object2 = new S3Object(s3HdfsPath1.getObjectName());
object2.setDataInputFile(file2);
s3Service.putObject(s3HdfsPath1.getBucketName(), object1);
s3Service.putObject(s3HdfsPath1.getBucketName(), object2);
FileStatus[] fs =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(2, fs.length);
FileStatus defaultObj = hdfs.getFileStatus(new Path(s3HdfsPath1.getFullHdfsObjPath()));
FileStatus versionObj;
if (fs[0].getPath().getName().equals(DEFAULT_VERSION)) {
assertTrue(fs[1].getPath().getName().matches("[0-9A-z.-]+"));
s3HdfsPath1.setVersion(fs[1].getPath().getName());
} else {
assertTrue(fs[0].getPath().getName().matches("[0-9A-z.-]+"));
assertEquals(DEFAULT_VERSION, fs[1].getPath().getName());
s3HdfsPath1.setVersion(fs[0].getPath().getName());
}
versionObj = hdfs.getFileStatus(new Path(s3HdfsPath1.getFullHdfsObjPath()));
assertEquals(SMALL_SIZE, defaultObj.getLen());
assertEquals(BIG_SIZE, versionObj.getLen());
}
示例9: testGetByVersionIds
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testGetByVersionIds()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
// Enable versioning
S3Bucket retBucket =
s3Service.createBucket(new S3Bucket(s3HdfsPath1.getBucketName()));
s3Service.enableBucketVersioning(retBucket.getName());
// Put new object
File file1 = testUtil.getFile(BIG_SIZE);
File file2 = testUtil.getFile(SMALL_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
object1.setDataInputFile(file1);
S3Object object2 = new S3Object(s3HdfsPath1.getObjectName());
object2.setDataInputFile(file2);
s3Service.putObject(s3HdfsPath1.getBucketName(), object1);
s3Service.putObject(s3HdfsPath1.getBucketName(), object2);
FileStatus[] fs =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(2, fs.length);
if (fs[0].getPath().getName().equals(DEFAULT_VERSION)) {
assertTrue(fs[1].getPath().getName().matches("[0-9A-z.-]+"));
s3HdfsPath1.setVersion(fs[1].getPath().getName());
} else {
assertTrue(fs[0].getPath().getName().matches("[0-9A-z.-]+"));
assertEquals(DEFAULT_VERSION, fs[1].getPath().getName());
s3HdfsPath1.setVersion(fs[0].getPath().getName());
}
S3Object defaultObj = s3Service.getVersionedObject(DEFAULT_VERSION,
s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
S3Object versionObj = s3Service.getVersionedObject(s3HdfsPath1.getVersion(),
s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
System.out.println(defaultObj.toString());
System.out.println(versionObj.toString());
}
示例10: testDeleteMarkerCreation
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testDeleteMarkerCreation()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
// Enable versioning
S3Bucket retBucket =
s3Service.createBucket(new S3Bucket(s3HdfsPath1.getBucketName()));
s3Service.enableBucketVersioning(retBucket.getName());
// Put new object
File file1 = testUtil.getFile(BIG_SIZE);
File file2 = testUtil.getFile(SMALL_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
object1.setDataInputFile(file1);
S3Object object2 = new S3Object(s3HdfsPath1.getObjectName());
object2.setDataInputFile(file2);
s3Service.putObject(s3HdfsPath1.getBucketName(), object1);
s3Service.putObject(s3HdfsPath1.getBucketName(), object2);
FileStatus[] fs =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(2, fs.length);
s3Service.deleteObject(s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
try {
s3Service.getObject(s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
} catch (S3ServiceException e) {
assertNotNull(e.getResponseHeaders().get("x-amz-delete-marker"));
assertEquals("true", e.getResponseHeaders().get("x-amz-delete-marker"));
}
FileStatus[] fs2 =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(3, fs2.length);
}
示例11: testDeleteMarkerDeletionAndPromotion
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testDeleteMarkerDeletionAndPromotion()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
// Enable versioning
S3Bucket retBucket =
s3Service.createBucket(new S3Bucket(s3HdfsPath1.getBucketName()));
s3Service.enableBucketVersioning(retBucket.getName());
// Put new object
File file1 = testUtil.getFile(BIG_SIZE);
File file2 = testUtil.getFile(SMALL_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
object1.setDataInputFile(file1);
S3Object object2 = new S3Object(s3HdfsPath1.getObjectName());
object2.setDataInputFile(file2);
s3Service.putObject(s3HdfsPath1.getBucketName(), object1);
s3Service.putObject(s3HdfsPath1.getBucketName(), object2);
FileStatus[] fs =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(2, fs.length);
s3Service.deleteObject(s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
FileStatus[] fs2 =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(3, fs2.length);
BaseVersionOrDeleteMarker[] versions =
s3Service.getObjectVersions(s3HdfsPath1.getBucketName(),
s3HdfsPath1.getObjectName());
for (BaseVersionOrDeleteMarker version : versions) {
System.out.println(version.toString());
if (version.isDeleteMarker()) {
// This will delete the latest version, causing promotion to occur.
s3Service.deleteVersionedObject(version.getVersionId(),
s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
}
}
FileStatus[] fs3 =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(2, fs3.length);
}
示例12: testListVersions
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testListVersions()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
// Enable versioning
S3Bucket retBucket =
s3Service.createBucket(new S3Bucket(s3HdfsPath1.getBucketName()));
s3Service.enableBucketVersioning(retBucket.getName());
// Put new object
File file1 = testUtil.getFile(BIG_SIZE);
File file2 = testUtil.getFile(SMALL_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
object1.setDataInputFile(file1);
S3Object object2 = new S3Object(s3HdfsPath1.getObjectName());
object2.setDataInputFile(file2);
s3Service.putObject(s3HdfsPath1.getBucketName(), object1);
s3Service.putObject(s3HdfsPath1.getBucketName(), object2);
FileStatus[] fs =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(2, fs.length);
if (fs[0].getPath().getName().equals(DEFAULT_VERSION)) {
assertTrue(fs[1].getPath().getName().matches("[0-9A-z.-]+"));
s3HdfsPath1.setVersion(fs[1].getPath().getName());
} else {
assertTrue(fs[0].getPath().getName().matches("[0-9A-z.-]+"));
assertEquals(DEFAULT_VERSION, fs[1].getPath().getName());
s3HdfsPath1.setVersion(fs[0].getPath().getName());
}
BaseVersionOrDeleteMarker[] versions = s3Service.getObjectVersions(
s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
System.out.println(versions[0].toString());
System.out.println(versions[1].toString());
}
示例13: testGetDefaultObjectByVersion
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Test
public void testGetDefaultObjectByVersion()
throws IOException, URISyntaxException,
ServiceException, NoSuchAlgorithmException {
S3HdfsPath s3HdfsPath1 = testUtil.setUpS3HdfsPath("folder", "file1");
// Enable versioning
S3Bucket retBucket =
s3Service.createBucket(new S3Bucket(s3HdfsPath1.getBucketName()));
s3Service.enableBucketVersioning(retBucket.getName());
// Put new object
File file1 = testUtil.getFile(BIG_SIZE);
File file2 = testUtil.getFile(SMALL_SIZE);
S3Object object1 = new S3Object(s3HdfsPath1.getObjectName());
object1.setDataInputFile(file1);
S3Object object2 = new S3Object(s3HdfsPath1.getObjectName());
object2.setDataInputFile(file2);
s3Service.putObject(s3HdfsPath1.getBucketName(), object1);
s3Service.putObject(s3HdfsPath1.getBucketName(), object2);
FileStatus[] fs =
hdfs.listStatus(new Path(s3HdfsPath1.getHdfsRootObjectPath()));
assertEquals(2, fs.length);
if (fs[0].getPath().getName().equals(DEFAULT_VERSION)) {
assertTrue(fs[1].getPath().getName().matches("[0-9A-z.-]+"));
s3HdfsPath1.setVersion(fs[1].getPath().getName());
} else {
assertTrue(fs[0].getPath().getName().matches("[0-9A-z.-]+"));
assertEquals(DEFAULT_VERSION, fs[1].getPath().getName());
s3HdfsPath1.setVersion(fs[0].getPath().getName());
}
DataInputStream data = hdfs.open(new Path(
s3HdfsPath1.getHdfsRootObjectPath() + "/" + DEFAULT_VERSION + "/" +
VERSION_FILE_NAME
));
String defaultVersion = testUtil.readInputStream(data);
System.out.println("Default version: " + defaultVersion);
S3Object defaultObj = s3Service.getVersionedObject(defaultVersion,
s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
S3Object versionObj = s3Service.getVersionedObject(s3HdfsPath1.getVersion(),
s3HdfsPath1.getBucketName(), s3HdfsPath1.getObjectName());
System.out.println(defaultObj.toString());
System.out.println(versionObj.toString());
}