public void put(String path, byte[] value) { try { S3Object obj = new S3Object(path, value); m_s3service.putObject(BUCKET, obj); m_logger.trace("PutObject: {}", path); inc(); } catch (Exception e) { throw new RuntimeException(e); } }
/** * * @param containerName * @param objectName * @param fileToSend * @throws StorageCommunicationException * @see org.opencredo.cloud.storage.StorageOperations#send(java.lang.String, * java.lang.String, java.io.File) */ public void send(String containerName, String objectName, File fileToSend) throws StorageCommunicationException { Assert.notNull(containerName, "Bucket name can not be null"); Assert.hasText(objectName, "Blob name must be set"); Assert.notNull(fileToSend, "File to send can not be null"); if (LOG.isDebugEnabled()) { LOG.debug("Send file '{}' to bucket '{}' with key '{}'", new Object[] { fileToSend.getAbsolutePath(), containerName, objectName }); } try { S3Object object = new S3Object(fileToSend); object.setKey(objectName); s3Service.putObject(new S3Bucket(containerName), object); } catch (S3ServiceException e) { throw new StorageCommunicationException("Sending file problem", e); } catch (NoSuchAlgorithmException e) { throw new StorageCommunicationException("No such algorithm", e); } catch (IOException e) { throw new StorageCommunicationException("Sending string IO problem", e); } }
/** * * @param containerName * @param objectName * @param stringToSend * @throws StorageCommunicationException * @see org.opencredo.cloud.storage.StorageOperations#send(java.lang.String, * java.lang.String, java.lang.String) */ public void send(String containerName, String objectName, String stringToSend) throws StorageCommunicationException { Assert.notNull(containerName, "Bucket name cannot be null"); Assert.hasText(objectName, "Blob name must be set"); LOG.debug("Send string to bucket '{}' with key '{}'", containerName, objectName); try { s3Service.putObject(new S3Bucket(containerName), new S3Object(objectName, stringToSend)); } catch (S3ServiceException e) { throw new StorageCommunicationException("Sending string problem", e); } catch (NoSuchAlgorithmException e) { throw new StorageCommunicationException("No such algorithm", e); } catch (IOException e) { throw new StorageCommunicationException("Sending string IO problem", e); } }
/** * * @param containerName * @param objectName * @param is * @throws StorageCommunicationException * @see org.opencredo.cloud.storage.StorageOperations#send(java.lang.String, * java.lang.String, java.io.InputStream) */ public void send(String containerName, String objectName, InputStream is) throws StorageCommunicationException { Assert.notNull(containerName, "Bucket name cannot be null"); Assert.hasText(objectName, "Blob name must be set"); LOG.debug("Send input-stream to bucket '{}' with key '{}'", containerName, objectName); try { S3Object s3ObjectToSend = new S3Object(objectName); s3ObjectToSend.setDataInputStream(is); s3ObjectToSend.setContentLength(is.available()); s3Service.putObject(new S3Bucket(containerName), s3ObjectToSend); } catch (IOException e) { throw new StorageCommunicationException("Sending input stream IO problem", e); } catch (S3ServiceException e) { throw new StorageCommunicationException("Sending input stream problem", e); } }
@Override public void mkdir() throws IOException { if(exists()) throw new IOException(); try { atts.setAttributes(service.putObject(bucketName, new org.jets3t.service.model.S3Object(getObjectKey(true)))); atts.setExists(true); atts.updateExpirationDate(); } catch(S3ServiceException e) { throw getIOException(e); } }
try { S3Object s3Object = new S3Object(new File(filePath)); s3.putObject(bucket, s3Object);
@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); } }
/** * Puts an object inside an existing bucket in S3, creating a new object or overwriting * an existing one with the same key. * <p> * This method can be performed by anonymous services. Anonymous services * can put objects into a publicly-writable bucket. * * @param bucket * the bucket inside which the object will be put, which must be valid. * @param object * the object containing all information that will be written to S3. At very least this object must * be valid. Beyond that it may contain: an input stream with the object's data content, metadata, * and access control settings.<p> * <b>Note:</b> It is very important to set the object's Content-Length to match the size of the * data input stream when possible, as this can remove the need to read data into memory to * determine its size. * * @return * the object populated with any metadata information made available by S3. * @throws S3ServiceException */ public S3Object putObject(S3Bucket bucket, S3Object object) throws S3ServiceException { try { assertValidBucket(bucket, "Create Object in bucket"); return putObject(bucket.getName(), object); } catch (ServiceException se) { throw new S3ServiceException(se); } }
public void storeFile(String key, File file, byte[] md5Hash) throws IOException { BufferedInputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); S3Object object = new S3Object(key); object.setDataInputStream(in); object.setContentType("binary/octet-stream"); object.setContentLength(file.length()); if (md5Hash != null) { object.setMd5Hash(md5Hash); } s3Service.putObject(bucket, object); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore } } } }
public void storeFile(String key, File file, byte[] md5Hash) throws IOException { BufferedInputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); S3Object object = new S3Object(key); object.setDataInputStream(in); object.setContentType("binary/octet-stream"); object.setContentLength(file.length()); if (md5Hash != null) { object.setMd5Hash(md5Hash); } s3Service.putObject(bucket, object); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore } } } }
/** * Puts an object inside an existing bucket in S3, creating a new object or overwriting * an existing one with the same key. * <p> * This method can be performed by anonymous services. Anonymous services * can put objects into a publicly-writable bucket. * * @param bucket * the bucket inside which the object will be put, which must be valid. * @param object * the object containing all information that will be written to S3. At very least this object must * be valid. Beyond that it may contain: an input stream with the object's data content, metadata, * and access control settings.<p> * <b>Note:</b> It is very important to set the object's Content-Length to match the size of the * data input stream when possible, as this can remove the need to read data into memory to * determine its size. * * @return * the object populated with any metadata information made available by S3. * @throws S3ServiceException */ public S3Object putObject(S3Bucket bucket, S3Object object) throws S3ServiceException { try { assertValidBucket(bucket, "Create Object in bucket"); return putObject(bucket.getName(), object); } catch (ServiceException se) { throw new S3ServiceException(se); } }
@Override public void storeFile(String key, File file, byte[] md5Hash) throws IOException { if (multipartEnabled && file.length() >= multipartBlockSize) { storeLargeFile(key, file, md5Hash); return; } BufferedInputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); S3Object object = new S3Object(key); object.setDataInputStream(in); object.setContentType("binary/octet-stream"); object.setContentLength(file.length()); object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm); if (md5Hash != null) { object.setMd5Hash(md5Hash); } s3Service.putObject(bucket, object); } catch (ServiceException e) { handleException(e, key); } finally { IOUtils.closeStream(in); } }
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); } }
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); } }
public void run() { try { File underlyingFile = s3Object.getDataInputFile(); if (s3Object.getDataInputStream() != null) { interruptableInputStream = new InterruptableInputStream(s3Object.getDataInputStream()); ProgressMonitoredInputStream pmInputStream = new ProgressMonitoredInputStream( interruptableInputStream, progressMonitor); s3Object.setDataInputStream(pmInputStream); } result = s3Service.putObject(bucket, s3Object); if (underlyingFile instanceof TempFile) { underlyingFile.delete(); } } catch (ServiceException se) { result = new S3ServiceException(se); } }
public void run() { try { File underlyingFile = s3Object.getDataInputFile(); if (s3Object.getDataInputStream() != null) { interruptableInputStream = new InterruptableInputStream(s3Object.getDataInputStream()); ProgressMonitoredInputStream pmInputStream = new ProgressMonitoredInputStream( interruptableInputStream, progressMonitor); s3Object.setDataInputStream(pmInputStream); } result = s3Service.putObject(bucket, s3Object); if (underlyingFile instanceof TempFile) { underlyingFile.delete(); } } catch (ServiceException se) { result = new S3ServiceException(se); } }
atts.setAttributes(service.putObject(bucketName, object)); atts.setExists(true); atts.updateExpirationDate();
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); } }
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); } }
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); } }