org.jets3t.service.model.S3Object Java Examples
The following examples show how to use
org.jets3t.service.model.S3Object.
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: 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 #2
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 #3
Source File: Jets3tNativeFileSystemStore.java From RDFS with Apache License 2.0 | 6 votes |
public void dump() throws IOException { StringBuilder sb = new StringBuilder("S3 Native Filesystem, "); sb.append(bucket.getName()).append("\n"); try { S3Object[] objects = s3Service.listObjects(bucket); for (int i = 0; i < objects.length; i++) { sb.append(objects[i].getKey()).append("\n"); } } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } System.out.println(sb); }
Example #4
Source File: Jets3tFileSystemStore.java From RDFS with Apache License 2.0 | 6 votes |
private InputStream get(String key, boolean checkMetadata) throws IOException { try { S3Object object = s3Service.getObject(bucket, key); if (checkMetadata) { checkMetadata(object); } return object.getDataInputStream(); } catch (S3ServiceException e) { if ("NoSuchKey".equals(e.getS3ErrorCode())) { return null; } if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #5
Source File: S3MetadataFeatureTest.java From cyberduck with GNU General Public License v3.0 | 6 votes |
@Test public void testSetMetadataFileLeaveOtherFeatures() throws Exception { final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); new S3TouchFeature(session).touch(test, new TransferStatus()); final String v = UUID.randomUUID().toString(); final S3StorageClassFeature storage = new S3StorageClassFeature(session); storage.setClass(test, S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY); assertEquals(S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY, storage.getClass(test)); final S3EncryptionFeature encryption = new S3EncryptionFeature(session); encryption.setEncryption(test, S3EncryptionFeature.SSE_AES256); assertEquals("AES256", encryption.getEncryption(test).algorithm); final S3MetadataFeature feature = new S3MetadataFeature(session, new S3AccessControlListFeature(session)); feature.setMetadata(test, Collections.singletonMap("Test", v)); final Map<String, String> metadata = feature.getMetadata(test); assertFalse(metadata.isEmpty()); assertTrue(metadata.containsKey("test")); assertEquals(v, metadata.get("test")); assertEquals(S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY, storage.getClass(test)); assertEquals("AES256", encryption.getEncryption(test).algorithm); new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
Example #6
Source File: TestGrantAcl.java From suro with Apache License 2.0 | 6 votes |
@Test public void test() throws Exception { RestS3Service s3Service = mock(RestS3Service.class); AccessControlList acl = new AccessControlList(); doReturn(acl).when(s3Service).getObjectAcl("bucket", "key"); doNothing().when(s3Service).putObjectAcl("bucket", "key", acl); GrantAcl grantAcl = new GrantAcl(s3Service, "1,2,3", 1); S3Object obj = new S3Object("key"); obj.setBucketName("bucket"); obj.setAcl(GSAccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL); assertTrue(grantAcl.grantAcl(obj)); Set<GrantAndPermission> grants = new HashSet<GrantAndPermission>(Arrays.asList(acl.getGrantAndPermissions())); assertEquals(grants.size(), 3); Set<GrantAndPermission> grantSet = new HashSet<GrantAndPermission>(); for (int i = 1; i <= 3; ++i) { grantSet.add(new GrantAndPermission(new CanonicalGrantee(Integer.toString(i)), Permission.PERMISSION_READ)); } }
Example #7
Source File: Jets3tFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
public Set<Path> listSubPaths(Path path) throws IOException { try { String prefix = pathToKey(path); if (!prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3Object[] objects = s3Service.listObjects(bucket, prefix, PATH_DELIMITER); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } prefixes.remove(path); return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #8
Source File: Jets3tNativeFileSystemStore.java From RDFS with Apache License 2.0 | 6 votes |
public FileMetadata retrieveMetadata(String key) throws IOException { try { S3Object object = s3Service.getObjectDetails(bucket, key); return new FileMetadata(key, object.getContentLength(), object.getLastModifiedDate().getTime()); } catch (S3ServiceException e) { // Following is brittle. Is there a better way? if (e.getMessage().contains("ResponseCode=404")) { return null; } if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #9
Source File: Jets3tNativeFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
public InputStream retrieve(String key, long byteRangeStart) throws IOException { try { S3Object object = s3Service.getObject(bucket, key, null, null, null, null, byteRangeStart, null); return object.getDataInputStream(); } catch (S3ServiceException e) { if ("NoSuchKey".equals(e.getS3ErrorCode())) { return null; } if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #10
Source File: Jets3tNativeFileSystemStore.java From hadoop with Apache License 2.0 | 6 votes |
/** * * @param key * The key is the object name that is being retrieved from the S3 bucket * @return * This method returns null if the key is not found * @throws IOException */ @Override public InputStream retrieve(String key, long byteRangeStart) throws IOException { try { LOG.debug("Getting key: {} from bucket: {} with byteRangeStart: {}", key, bucket.getName(), byteRangeStart); S3Object object = s3Service.getObject(bucket, key, null, null, null, null, byteRangeStart, null); return object.getDataInputStream(); } catch (ServiceException e) { handleException(e, key); return null; } }
Example #11
Source File: Jets3tNativeFileSystemStore.java From hadoop with Apache License 2.0 | 6 votes |
@Override public void copy(String srcKey, String dstKey) throws IOException { try { if(LOG.isDebugEnabled()) { LOG.debug("Copying srcKey: " + srcKey + "to dstKey: " + dstKey + "in bucket: " + bucket.getName()); } if (multipartEnabled) { S3Object object = s3Service.getObjectDetails(bucket, srcKey, null, null, null, null); if (multipartCopyBlockSize > 0 && object.getContentLength() > multipartCopyBlockSize) { copyLargeFile(object, dstKey); return; } } S3Object dstObject = new S3Object(dstKey); dstObject.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm); s3Service.copyObject(bucket.getName(), srcKey, bucket.getName(), dstObject, false); } catch (ServiceException e) { handleException(e, srcKey); } }
Example #12
Source File: Jets3tFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
private InputStream get(String key, boolean checkMetadata) throws IOException { try { S3Object object = s3Service.getObject(bucket, key); if (checkMetadata) { checkMetadata(object); } return object.getDataInputStream(); } catch (S3ServiceException e) { if ("NoSuchKey".equals(e.getS3ErrorCode())) { return null; } if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #13
Source File: GrantAcl.java From suro with Apache License 2.0 | 6 votes |
public boolean grantAcl(S3Object object) throws ServiceException, InterruptedException { if(Strings.isNullOrEmpty(s3Acl)){ return true; } for (int i = 0; i < s3AclRetries; ++i) { try { AccessControlList acl = s3Service.getObjectAcl(object.getBucketName(), object.getKey()); for (String id : s3Acl.split(",")) { acl.grantPermission(new CanonicalGrantee(id), Permission.PERMISSION_READ); } s3Service.putObjectAcl(object.getBucketName(), object.getKey(), acl); return true; } catch (Exception e) { log.error("Exception while granting ACL: " + e.getMessage(), e); Thread.sleep(1000 * (i + 1)); } } return false; }
Example #14
Source File: Jets3tNativeFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
private PartialListing list(String prefix, String delimiter, int maxListingLength, String priorLastKey) throws IOException { try { if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3ObjectsChunk chunk = s3Service.listObjectsChunked(bucket.getName(), prefix, delimiter, maxListingLength, priorLastKey); FileMetadata[] fileMetadata = new FileMetadata[chunk.getObjects().length]; for (int i = 0; i < fileMetadata.length; i++) { S3Object object = chunk.getObjects()[i]; fileMetadata[i] = new FileMetadata(object.getKey(), object.getContentLength(), object.getLastModifiedDate().getTime()); } return new PartialListing(chunk.getPriorLastKey(), fileMetadata, chunk.getCommonPrefixes()); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #15
Source File: Jets3tFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
public Set<Path> listDeepSubPaths(Path path) throws IOException { try { String prefix = pathToKey(path); if (!prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3Object[] objects = s3Service.listObjects(bucket, prefix, null); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } prefixes.remove(path); return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #16
Source File: AmazonConnection.java From Doradus with Apache License 2.0 | 6 votes |
public byte[] get(String path) { try { S3Object obj = m_s3service.getObject(BUCKET, path); m_logger.trace("GetObject: {}", path); inc(); if(obj == null) return null; int len = (int)obj.getContentLength(); byte[] data = new byte[len]; int start = 0; InputStream is = obj.getDataInputStream(); while(start < len) { start += is.read(data, start, len - start); } is.close(); return data; } catch (Exception e) { return null; } }
Example #17
Source File: JetS3tLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void givenStringUploaded_StringIsDownloaded() throws Exception { // Get a bucket S3Bucket bucket = createBucket(); assertNotNull(bucket); uploadStringData(); // Download S3Object stringObject = s3Service.getObject(BucketName, TestStringName); // Process stream into a string String downloadedString = new BufferedReader(new InputStreamReader(stringObject.getDataInputStream())).lines().collect(Collectors.joining("\n")); // Verify assertTrue(TestString.equals(downloadedString)); // Clean up for next test deleteObject(TestStringName); deleteBucket(); }
Example #18
Source File: MigrationTool.java From big-c with Apache License 2.0 | 6 votes |
@Override public Set<Path> listAllPaths() throws IOException { try { String prefix = urlEncode(Path.SEPARATOR); S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, null); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #19
Source File: Jets3tNativeFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
public void dump() throws IOException { StringBuilder sb = new StringBuilder("S3 Native Filesystem, "); sb.append(bucket.getName()).append("\n"); try { S3Object[] objects = s3Service.listObjects(bucket); for (int i = 0; i < objects.length; i++) { sb.append(objects[i].getKey()).append("\n"); } } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } System.out.println(sb); }
Example #20
Source File: MigrationTool.java From hadoop with Apache License 2.0 | 6 votes |
@Override public Set<Path> listAllPaths() throws IOException { try { String prefix = urlEncode(Path.SEPARATOR); S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, null); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #21
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 #22
Source File: MigrationTool.java From RDFS with Apache License 2.0 | 6 votes |
public Set<Path> listAllPaths() throws IOException { try { String prefix = urlEncode(Path.SEPARATOR); S3Object[] objects = s3Service.listObjects(bucket, prefix, null); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #23
Source File: Jets3tNativeFileSystemStore.java From big-c with Apache License 2.0 | 6 votes |
/** * * @param key * The key is the object name that is being retrieved from the S3 bucket * @return * This method returns null if the key is not found * @throws IOException */ @Override public InputStream retrieve(String key, long byteRangeStart) throws IOException { try { LOG.debug("Getting key: {} from bucket: {} with byteRangeStart: {}", key, bucket.getName(), byteRangeStart); S3Object object = s3Service.getObject(bucket, key, null, null, null, null, byteRangeStart, null); return object.getDataInputStream(); } catch (ServiceException e) { handleException(e, key); return null; } }
Example #24
Source File: Jets3tFileSystemStore.java From big-c with Apache License 2.0 | 6 votes |
@Override public void dump() throws IOException { StringBuilder sb = new StringBuilder("S3 Filesystem, "); sb.append(bucket.getName()).append("\n"); try { S3Object[] objects = s3Service.listObjects(bucket.getName(), PATH_DELIMITER, null); for (int i = 0; i < objects.length; i++) { Path path = keyToPath(objects[i].getKey()); sb.append(path).append("\n"); INode m = retrieveINode(path); sb.append("\t").append(m.getFileType()).append("\n"); if (m.getFileType() == FileType.DIRECTORY) { continue; } for (int j = 0; j < m.getBlocks().length; j++) { sb.append("\t").append(m.getBlocks()[j]).append("\n"); } } } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } System.out.println(sb); }
Example #25
Source File: Jets3tNativeFileSystemStore.java From big-c with Apache License 2.0 | 6 votes |
@Override public void copy(String srcKey, String dstKey) throws IOException { try { if(LOG.isDebugEnabled()) { LOG.debug("Copying srcKey: " + srcKey + "to dstKey: " + dstKey + "in bucket: " + bucket.getName()); } if (multipartEnabled) { S3Object object = s3Service.getObjectDetails(bucket, srcKey, null, null, null, null); if (multipartCopyBlockSize > 0 && object.getContentLength() > multipartCopyBlockSize) { copyLargeFile(object, dstKey); return; } } S3Object dstObject = new S3Object(dstKey); dstObject.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm); s3Service.copyObject(bucket.getName(), srcKey, bucket.getName(), dstObject, false); } catch (ServiceException e) { handleException(e, srcKey); } }
Example #26
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 #27
Source File: Jets3tFileSystemStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
public void dump() throws IOException { StringBuilder sb = new StringBuilder("S3 Filesystem, "); sb.append(bucket.getName()).append("\n"); try { S3Object[] objects = s3Service.listObjects(bucket, PATH_DELIMITER, null); for (int i = 0; i < objects.length; i++) { Path path = keyToPath(objects[i].getKey()); sb.append(path).append("\n"); INode m = retrieveINode(path); sb.append("\t").append(m.getFileType()).append("\n"); if (m.getFileType() == FileType.DIRECTORY) { continue; } for (int j = 0; j < m.getBlocks().length; j++) { sb.append("\t").append(m.getBlocks()[j]).append("\n"); } } } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } System.out.println(sb); }
Example #28
Source File: Jets3tFileSystemStore.java From big-c with Apache License 2.0 | 6 votes |
private void checkMetadata(S3Object object) throws S3FileSystemException, S3ServiceException { String name = (String) object.getMetadata(FILE_SYSTEM_NAME); if (!FILE_SYSTEM_VALUE.equals(name)) { throw new S3FileSystemException("Not a Hadoop S3 file."); } String type = (String) object.getMetadata(FILE_SYSTEM_TYPE_NAME); if (!FILE_SYSTEM_TYPE_VALUE.equals(type)) { throw new S3FileSystemException("Not a block file."); } String dataVersion = (String) object.getMetadata(FILE_SYSTEM_VERSION_NAME); if (!FILE_SYSTEM_VERSION_VALUE.equals(dataVersion)) { throw new VersionMismatchException(FILE_SYSTEM_VERSION_VALUE, dataVersion); } }
Example #29
Source File: Jets3tFileSystemStore.java From big-c with Apache License 2.0 | 6 votes |
@Override public Set<Path> listSubPaths(Path path) throws IOException { try { String prefix = pathToKey(path); if (!prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, PATH_DELIMITER); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } prefixes.remove(path); return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
Example #30
Source File: Jets3tFileSystemStore.java From big-c with Apache License 2.0 | 6 votes |
@Override public Set<Path> listDeepSubPaths(Path path) throws IOException { try { String prefix = pathToKey(path); if (!prefix.endsWith(PATH_DELIMITER)) { prefix += PATH_DELIMITER; } S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, null); Set<Path> prefixes = new TreeSet<Path>(); for (int i = 0; i < objects.length; i++) { prefixes.add(keyToPath(objects[i].getKey())); } prefixes.remove(path); return prefixes; } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }