@Override public void close() throws IOException { if (mClosed.getAndSet(true)) { return; } mLocalOutputStream.close(); try { GSObject obj = new GSObject(mKey); obj.setBucketName(mBucketName); obj.setDataInputFile(mFile); obj.setContentLength(mFile.length()); obj.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM); if (mHash != null) { obj.setMd5Hash(mHash.digest()); } else { LOG.warn("MD5 was not computed for: {}", mKey); } mClient.putObject(mBucketName, obj); if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath()); } } catch (ServiceException e) { LOG.error("Failed to upload {}. Temporary file @ {}", mKey, mFile.getPath()); throw new IOException(e); } } }
@Override protected boolean createEmptyObject(String key) { try { GSObject obj = new GSObject(key); obj.setDataInputStream(new ByteArrayInputStream(new byte[0])); obj.setContentLength(0); obj.setMd5Hash(DIR_HASH); obj.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM); mClient.putObject(mBucketName, obj); return true; } catch (ServiceException e) { LOG.error("Failed to create directory: {}", key, e); return false; } }
@Override public void close() throws IOException { if (mClosed.getAndSet(true)) { return; } mLocalOutputStream.close(); try { GSObject obj = new GSObject(mKey); obj.setBucketName(mBucketName); obj.setDataInputFile(mFile); obj.setContentLength(mFile.length()); obj.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM); if (mHash != null) { obj.setMd5Hash(mHash.digest()); } else { LOG.warn("MD5 was not computed for: {}", mKey); } mClient.putObject(mBucketName, obj); if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath()); } } catch (ServiceException e) { LOG.error("Failed to upload {}. Temporary file @ {}", mKey, mFile.getPath()); throw new IOException(e); } } }
@Override protected boolean createEmptyObject(String key) { try { GSObject obj = new GSObject(key); obj.setDataInputStream(new ByteArrayInputStream(new byte[0])); obj.setContentLength(0); obj.setMd5Hash(DIR_HASH); obj.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM); mClient.putObject(mBucketName, obj); return true; } catch (ServiceException e) { LOG.error("Failed to create directory: {}", key, e); return false; } }
public void writeBlankChunk(String hash, byte[] chunk) throws IOException { String hashString = hash; GSObject gsObject = new GSObject(hashString); if (Main.compress) { chunk = CompressionUtils.compressZLIB(chunk); gsObject.addMetadata("compress", "true"); } else { gsObject.addMetadata("compress", "false"); } if (Main.chunkStoreEncryptionEnabled) { chunk = EncryptUtils.encrypt(chunk); gsObject.addMetadata("encrypt", "true"); } else { gsObject.addMetadata("encrypt", "false"); } ByteArrayInputStream s3IS = new ByteArrayInputStream(chunk); gsObject.setDataInputStream(s3IS); gsObject.setContentType("binary/octet-stream"); gsObject.setContentLength(s3IS.available()); try { gsService.putObject(this.getName(), gsObject); } catch (Exception e) { // TODO Auto-generated catch block SDFSLogger.getLog().fatal("unable to upload " + hashString, e); throw new IOException(e); } finally { s3IS.close(); } }
gsObject.setContentType("binary/octet-stream"); gsObject.setContentLength(s3IS.available()); try {
helloWorldObject.setContentLength( greeting.getBytes(Constants.DEFAULT_ENCODING).length); helloWorldObject.setContentType("text/plain");
helloWorldObject.setContentLength( greeting.getBytes(Constants.DEFAULT_ENCODING).length); helloWorldObject.setContentType("text/plain");