Java Code Examples for org.jets3t.service.model.S3Object#setContentType()
The following examples show how to use
org.jets3t.service.model.S3Object#setContentType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpectraWriteFeature.java From cyberduck with GNU General Public License v3.0 | 6 votes |
/** * Add default metadata. Do not add checksum as object metadata must remain constant for all chunks. */ 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: // Set checksum on our own to avoid jets3t setting AWS metadata for MD5 as metadata must remain // constant for all chunks object.addMetadata("Content-MD5", ServiceUtils.toBase64(ServiceUtils.fromHex(checksum.hash))); break; } } return object; }
Example 2
Source File: Jets3tNativeFileSystemStore.java From hadoop with Apache License 2.0 | 6 votes |
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); } }
Example 3
Source File: Jets3tFileSystemStore.java From hadoop with Apache License 2.0 | 6 votes |
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); } }
Example 4
Source File: Jets3tNativeFileSystemStore.java From big-c with Apache License 2.0 | 6 votes |
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); } }
Example 5
Source File: Jets3tFileSystemStore.java From big-c with Apache License 2.0 | 6 votes |
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); } }
Example 6
Source File: Jets3tFileSystemStore.java From RDFS with Apache License 2.0 | 6 votes |
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); } }
Example 7
Source File: Jets3tFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
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); } }
Example 8
Source File: S3WriteFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 9
Source File: Jets3tNativeFileSystemStore.java From hadoop with Apache License 2.0 | 5 votes |
@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); } }
Example 10
Source File: Jets3tNativeFileSystemStore.java From big-c with Apache License 2.0 | 5 votes |
@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); } }
Example 11
Source File: S3FilenameGenerator.java From red5-examples with Apache License 2.0 | 5 votes |
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); } }
Example 12
Source File: Jets3tNativeFileSystemStore.java From RDFS with Apache License 2.0 | 5 votes |
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); } }
Example 13
Source File: Jets3tNativeFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 5 votes |
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); } }
Example 14
Source File: JetS3tLiveTest.java From tutorials with MIT License | 4 votes |
@Test public void givenStreamDataUploaded_StreamDataIsDownloaded() throws Exception { // get a bucket S3Bucket bucket = createBucket(); assertNotNull(bucket); ArrayList<Integer> numbers = new ArrayList<>(); numbers.add(2); numbers.add(3); numbers.add(5); numbers.add(7); // Serialize ArrayList ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes); objectOutputStream.writeObject(numbers); // Wrap bytes ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray()); // Create and populate object S3Object streamObject = new S3Object("stream"); streamObject.setDataInputStream(byteArrayInputStream); streamObject.setContentLength(byteArrayInputStream.available()); streamObject.setContentType("binary/octet-stream"); // Put it s3Service.putObject(BucketName, streamObject); // Get it S3Object newStreamObject = s3Service.getObject(BucketName, "stream"); // Convert back to ArrayList ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream()); ArrayList<Integer> newNumbers = (ArrayList<Integer>)objectInputStream.readObject(); assertEquals(2, (int)newNumbers.get(0)); assertEquals(3, (int)newNumbers.get(1)); assertEquals(5, (int)newNumbers.get(2)); assertEquals(7, (int)newNumbers.get(3)); // Clean up deleteObject("stream"); deleteBucket(); }
Example 15
Source File: JetS3tLiveTest.java From tutorials with MIT License | 4 votes |
@Test public void givenStreamDataUploaded_StreamDataIsDownloaded() throws Exception { // get a bucket S3Bucket bucket = createBucket(); assertNotNull(bucket); ArrayList<Integer> numbers = new ArrayList<>(); numbers.add(2); numbers.add(3); numbers.add(5); numbers.add(7); // Serialize ArrayList ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes); objectOutputStream.writeObject(numbers); // Wrap bytes ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray()); // Create and populate object S3Object streamObject = new S3Object("stream"); streamObject.setDataInputStream(byteArrayInputStream); streamObject.setContentLength(byteArrayInputStream.available()); streamObject.setContentType("binary/octet-stream"); // Put it s3Service.putObject(BucketName, streamObject); // Get it S3Object newStreamObject = s3Service.getObject(BucketName, "stream"); // Convert back to ArrayList ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream()); ArrayList<Integer> newNumbers = (ArrayList<Integer>)objectInputStream.readObject(); assertEquals(2, (int)newNumbers.get(0)); assertEquals(3, (int)newNumbers.get(1)); assertEquals(5, (int)newNumbers.get(2)); assertEquals(7, (int)newNumbers.get(3)); // Clean up deleteObject("stream"); deleteBucket(); }