List of usage examples for com.amazonaws.services.s3.model S3Object getObjectMetadata
public ObjectMetadata getObjectMetadata()
From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserController.java
License:Apache License
@RequestMapping(value = "download", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK)/*from w w w . j a va 2 s . c o m*/ public Response download(HttpServletResponse res, @RequestParam String bucketName, @RequestParam String key) throws IOException { S3Object object = s3BrowserService.getObject(bucketName, key); InputStream objectData = object.getObjectContent(); res.setHeader("Content-Length", "" + object.getObjectMetadata().getContentLength()); res.setHeader("Content-Transfer-Encoding", "binary"); res.setHeader("Content-Type", "application/force-download"); res.setHeader("Content-Disposition", MessageFormatter.format("attachment; filename={};", getName(key)).getMessage()); res.setStatus(200); FileCopyUtils.copy(objectData, res.getOutputStream()); res.flushBuffer(); objectData.close(); Response response = new Response(); response.setSuccess(true); return response; }
From source file:org.geowebcache.s3.S3BlobStore.java
License:Open Source License
@Override public boolean get(TileObject obj) throws StorageException { final String key = keyBuilder.forTile(obj); final S3Object object = s3Ops.getObject(key); if (object == null) { return false; }// w w w. j a v a2 s. c o m try (S3ObjectInputStream in = object.getObjectContent()) { byte[] bytes = ByteStreams.toByteArray(in); obj.setBlobSize(bytes.length); obj.setBlob(new ByteArrayResource(bytes)); obj.setCreated(object.getObjectMetadata().getLastModified().getTime()); } catch (IOException e) { throw new StorageException("Error getting " + key, e); } return true; }
From source file:org.geowebcache.s3.S3Ops.java
License:Open Source License
private boolean isPendingDelete(S3Object object) { if (pendingDeletesKeyTime.isEmpty()) { return false; }// www . j a va 2 s .c om final String key = object.getKey(); final long lastModified = object.getObjectMetadata().getLastModified().getTime(); for (Map.Entry<String, Long> e : pendingDeletesKeyTime.entrySet()) { String parentKey = e.getKey(); if (key.startsWith(parentKey)) { long deleteTime = e.getValue().longValue(); return deleteTime >= lastModified; } } return false; }
From source file:org.gradle.internal.resource.transport.aws.s3.S3ResourceConnector.java
License:Apache License
public ExternalResourceMetaData getMetaData(URI location) { LOGGER.debug("Attempting to get resource metadata: {}", location); S3Object s3Object = s3Client.getMetaData(location); if (s3Object == null) { return null; }//from w ww . j a v a 2 s . c o m ObjectMetadata objectMetadata = s3Object.getObjectMetadata(); return new DefaultExternalResourceMetaData(location, objectMetadata.getLastModified().getTime(), objectMetadata.getContentLength(), objectMetadata.getContentType(), objectMetadata.getETag(), null); // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb) }
From source file:org.huahinframework.core.util.S3Utils.java
License:Apache License
/** * {@inheritDoc}//from w w w . j a v a 2s . c om */ @Override public long getFileSize(String path) throws IOException, URISyntaxException { URI uri = new URI(path); String key = uri.getPath().substring(1); S3Object s3Object = s3.getObject(uri.getHost(), key); return s3Object.getObjectMetadata().getContentLength(); }
From source file:org.jdamico.s3.components.S3Component.java
License:Apache License
public boolean isValidFile(AppProperties appProperties, String keyName) throws TopLevelException { AmazonS3 s3client = getS3Client(appProperties); boolean isValidFile = true; try {/*from w w w . j av a 2s. c om*/ S3Object object = s3client.getObject(new GetObjectRequest(appProperties.getBucketnName(), keyName)); ObjectMetadata objectMetadata = object.getObjectMetadata(); } catch (AmazonS3Exception s3e) { if (s3e.getStatusCode() == 404) { isValidFile = false; } else { throw new TopLevelException(appProperties, s3e); } } return isValidFile; }
From source file:org.opendedup.sdfs.filestore.cloud.BatchAwsS3ChunkStore.java
License:Open Source License
private String[] getStrings(S3Object sobj) throws IOException { this.s3clientLock.readLock().lock(); try {/*from w w w . j a v a 2 s . c om*/ boolean encrypt = false; boolean compress = false; boolean lz4compress = false; int cl = (int) sobj.getObjectMetadata().getContentLength(); byte[] data = new byte[cl]; DataInputStream in = null; try { in = new DataInputStream(sobj.getObjectContent()); in.readFully(data); } catch (Exception e) { throw new IOException(e); } finally { try { in.close(); } catch (Exception e) { } } Map<String, String> mp = this.getUserMetaData(sobj.getObjectMetadata()); if (mp.containsKey("md5sum")) { try { byte[] shash = BaseEncoding.base64().decode(mp.get("md5sum")); byte[] chash; chash = ServiceUtils.computeMD5Hash(data); if (!Arrays.equals(shash, chash)) throw new IOException("download corrupt at " + sobj.getKey()); } catch (NoSuchAlgorithmException e) { throw new IOException(e); } } int size = Integer.parseInt((String) mp.get("size")); if (mp.containsKey("encrypt")) { encrypt = Boolean.parseBoolean((String) mp.get("encrypt")); } if (mp.containsKey("compress")) { compress = Boolean.parseBoolean((String) mp.get("compress")); } else if (mp.containsKey("lz4compress")) { lz4compress = Boolean.parseBoolean((String) mp.get("lz4compress")); } byte[] ivb = null; if (mp.containsKey("ivspec")) ivb = BaseEncoding.base64().decode(mp.get("ivspec")); if (encrypt) { if (ivb != null) data = EncryptUtils.decryptCBC(data, new IvParameterSpec(ivb)); else data = EncryptUtils.decryptCBC(data); } if (compress) data = CompressionUtils.decompressZLIB(data); else if (lz4compress) { data = CompressionUtils.decompressLz4(data, size); } String hast = new String(data); SDFSLogger.getLog().debug("reading hashes " + (String) mp.get("hashes") + " from " + sobj.getKey()); String[] st = hast.split(","); return st; } finally { this.s3clientLock.readLock().unlock(); } }
From source file:org.opendedup.sdfs.filestore.cloud.BatchAwsS3ChunkStore.java
License:Open Source License
private int getClaimedObjects(S3Object sobj, long id) throws Exception, IOException { Map<String, String> mp = this.getUserMetaData(sobj.getObjectMetadata()); if (!mp.containsKey("encrypt")) { mp = this.getUserMetaData(s3Service.getObjectMetadata(this.name, sobj.getKey())); }/*from w w w. j ava 2 s . com*/ String[] st = this.getStrings(sobj); int claims = 0; for (String ha : st) { byte[] b = BaseEncoding.base64().decode(ha.split(":")[0]); if (HCServiceProxy.getHashesMap().mightContainKey(b)) claims++; } return claims; }
From source file:org.opendedup.sdfs.filestore.cloud.BatchAwsS3ChunkStore.java
License:Open Source License
public StringResult getStringResult(String key) throws IOException, InterruptedException { this.s3clientLock.readLock().lock(); S3Object sobj = null; try {//from w w w.j ava2s.c om ObjectMetadata md = null; try { sobj = s3Service.getObject(getName(), key); md = s3Service.getObjectMetadata(this.name, key); } catch (Exception e) { throw new IOException(e); } int cl = (int) md.getContentLength(); byte[] data = new byte[cl]; DataInputStream in = null; try { in = new DataInputStream(sobj.getObjectContent()); in.readFully(data); } catch (Exception e) { throw new IOException(e); } finally { if (in != null) in.close(); } boolean encrypt = false; boolean compress = false; boolean lz4compress = false; Map<String, String> mp = this.getUserMetaData(md); byte[] ivb = null; if (mp.containsKey("ivspec")) { ivb = BaseEncoding.base64().decode(mp.get("ivspec")); } if (mp.containsKey("md5sum")) { try { byte[] shash = BaseEncoding.base64().decode(mp.get("md5sum")); byte[] chash = ServiceUtils.computeMD5Hash(data); if (!Arrays.equals(shash, chash)) throw new IOException("download corrupt at " + sobj.getKey()); } catch (NoSuchAlgorithmException e) { throw new IOException(e); } } int size = Integer.parseInt(mp.get("size")); encrypt = Boolean.parseBoolean(mp.get("encrypt")); lz4compress = Boolean.parseBoolean(mp.get("lz4compress")); boolean changed = false; Long hid = EncyptUtils.decHashArchiveName(sobj.getKey().substring(5), encrypt); if (this.clustered) mp = s3Service.getObjectMetadata(this.name, this.getClaimName(hid)).getUserMetadata(); if (mp.containsKey("deleted")) { mp.remove("deleted"); changed = true; } if (mp.containsKey("deleted-objects")) { mp.remove("deleted-objects"); changed = true; } if (encrypt) { if (ivb != null) { data = EncryptUtils.decryptCBC(data, new IvParameterSpec(ivb)); } else { data = EncryptUtils.decryptCBC(data); } } if (compress) data = CompressionUtils.decompressZLIB(data); else if (lz4compress) { data = CompressionUtils.decompressLz4(data, size); } String hast = new String(data); SDFSLogger.getLog().debug("reading hashes " + (String) mp.get("objects") + " from " + hid + " encn " + sobj.getKey().substring(5)); StringTokenizer ht = new StringTokenizer(hast, ","); StringResult st = new StringResult(); st.id = hid; st.st = ht; if (mp.containsKey("bsize")) { HashBlobArchive.currentLength.addAndGet(Integer.parseInt(mp.get("bsize"))); } if (mp.containsKey("bcompressedsize")) { HashBlobArchive.compressedLength.addAndGet(Integer.parseInt(mp.get("bcompressedsize"))); } if (changed) { try { md = sobj.getObjectMetadata(); md.setUserMetadata(mp); String kn = null; if (this.clustered) kn = this.getClaimName(hid); else kn = sobj.getKey(); this.updateObject(kn, md); } catch (Exception e) { throw new IOException(e); } } return st; } finally { if (sobj != null) sobj.close(); this.s3clientLock.readLock().unlock(); } }
From source file:org.openflamingo.fs.s3.S3DirectoryInfo.java
License:Apache License
/** * ??// w w w . ja v a 2 s .c o m * * @param object Amazon S3 Object */ public S3DirectoryInfo(S3Object object) { this.fullyQualifiedPath = object.getBucketName() + "/" + object.getKey(); this.path = FileUtils.getPath(this.fullyQualifiedPath); this.length = object.getObjectMetadata().getContentLength(); this.modificationTime = object.getObjectMetadata().getLastModified().getTime(); this.accesTime = object.getObjectMetadata().getLastModified().getTime(); }