/** * Counts the total number of bytes in a set of S3Objects by summing the * content length of each. * * @param objects * @return * total number of bytes in all S3Objects. */ public static long countBytesInObjects(S3Object[] objects) { long byteTotal = 0; for (int i = 0; objects != null && i < objects.length; i++) { byteTotal += objects[i].getContentLength(); } return byteTotal; }
/** * Counts the total number of bytes in a set of S3Objects by summing the * content length of each. * * @param objects * @return * total number of bytes in all S3Objects. */ public static long countBytesInObjects(S3Object[] objects) { long byteTotal = 0; for (int i = 0; objects != null && i < objects.length; i++) { byteTotal += objects[i].getContentLength(); } return byteTotal; }
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; } }
public int addObject(S3Object object) { int insertRow = Collections.binarySearch(objectList, object, new Comparator() { public int compare(Object o1, Object o2) { return ((S3Object)o1).getKey().compareToIgnoreCase(((S3Object)o2).getKey()); } }); if (insertRow >= 0) { // We already have an item with this key, replace it. objectList.remove(insertRow); this.removeRow(insertRow); } else { insertRow = (-insertRow) - 1; } // New object to insert. objectList.add(insertRow, object); this.insertRow(insertRow, new Object[] {object.getKey(), new Long(object.getContentLength()), object.getLastModifiedDate()}); return insertRow; }
public int addObject(S3Object object) { int insertRow = Collections.binarySearch(objectList, object, new Comparator() { public int compare(Object o1, Object o2) { return ((S3Object)o1).getKey().compareToIgnoreCase(((S3Object)o2).getKey()); } }); if (insertRow >= 0) { // We already have an item with this key, replace it. objectList.remove(insertRow); this.removeRow(insertRow); } else { insertRow = (-insertRow) - 1; } // New object to insert. objectList.add(insertRow, object); this.insertRow(insertRow, new Object[] {object.getKey(), new Long(object.getContentLength()), object.getLastModifiedDate()}); return insertRow; }
totalBytes += objects[i].getContentLength();
totalBytes += objects[i].getContentLength();
totalBytes += objects[i].getContentLength();
totalBytes += objects[i].getContentLength();
public void copyLargeFile(S3Object srcObject, String dstKey) throws IOException { try { long partCount = srcObject.getContentLength() / multipartCopyBlockSize + (srcObject.getContentLength() % multipartCopyBlockSize > 0 ? 1 : 0); byteLength = multipartCopyBlockSize; } else { byteLength = srcObject.getContentLength() % multipartCopyBlockSize; if (byteLength == 0) { byteLength = multipartCopyBlockSize;
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); } }
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); } }
private void setAttributes(org.jets3t.service.model.S3Object object) { setDirectory(object.getKey().endsWith("/")); setSize(object.getContentLength()); setDate(object.getLastModifiedDate().getTime()); setPermissions(DEFAULT_PERMISSIONS); // Note: owner is null for common prefix objects S3Owner owner = object.getOwner(); setOwner(owner==null?null:owner.getDisplayName()); }
public int addObject(S3Object object) { sanitizeObjectKey(object); int insertRow = Collections.binarySearch(objectList, object, new Comparator() { public int compare(Object o1, Object o2) { return ((S3Object)o1).getKey().compareToIgnoreCase(((S3Object)o2).getKey()); } }); String aclStatus = null; if (insertRow >= 0) { // Retain the object's ACL status if it's available. aclStatus = (String) this.getValueAt(insertRow, 3); // We already have an item with this key, replace it. objectList.remove(insertRow); this.removeRow(insertRow); } else { insertRow = (-insertRow) - 1; } if (object.getAcl() != null || aclStatus == null) { aclStatus = CockpitLite.getAclDescription(object.getAcl()); } // New object to insert. objectList.add(insertRow, object); this.insertRow(insertRow, new Object[] {object.getKey(), new Long(object.getContentLength()), object.getLastModifiedDate(), aclStatus}); return insertRow; }
public int addObject(S3Object object) { sanitizeObjectKey(object); int insertRow = Collections.binarySearch(objectList, object, new Comparator() { public int compare(Object o1, Object o2) { return ((S3Object)o1).getKey().compareToIgnoreCase(((S3Object)o2).getKey()); } }); String aclStatus = null; if (insertRow >= 0) { // Retain the object's ACL status if it's available. aclStatus = (String) this.getValueAt(insertRow, 3); // We already have an item with this key, replace it. objectList.remove(insertRow); this.removeRow(insertRow); } else { insertRow = (-insertRow) - 1; } if (object.getAcl() != null || aclStatus == null) { aclStatus = CockpitLite.getAclDescription(object.getAcl()); } // New object to insert. objectList.add(insertRow, object); this.insertRow(insertRow, new Object[] {object.getKey(), new Long(object.getContentLength()), object.getLastModifiedDate(), aclStatus}); return insertRow; }
null == part.getLastModifiedDate() ? new Date(System.currentTimeMillis()) : part.getLastModifiedDate(), null == part.getETag() ? StringUtils.EMPTY : part.getETag(), part.getContentLength());
@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); } }
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); } }
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); } }
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final HttpRange range = HttpRange.withStatus(status); final RequestEntityRestStorageService client = session.getClient(); final S3Object object = client.getVersionedObject( file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file), null, // ifModifiedSince null, // ifUnmodifiedSince null, // ifMatch null, // ifNoneMatch status.isAppend() ? range.getStart() : null, status.isAppend() ? (range.getEnd() == -1 ? null : range.getEnd()) : null); if(log.isDebugEnabled()) { log.debug(String.format("Reading stream with content length %d", object.getContentLength())); } return object.getDataInputStream(); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Download {0} failed", e, file); } }