/** * Creates a copy of an existing S3 Object. In this signature, we will copy the * existing metadata. The default access control policy is private; if you want * to override it, please use x-amz-acl in the headers. * @param sourceBucket The name of the bucket where the source object lives. * @param sourceKey The name of the key to copy. * @param destinationBucket The name of the bucket to which the object will be added. * @param destinationKey The name of the key to use. * @param headers A Map of String to List of Strings representing the http * headers to pass (can be null). You may wish to set the x-amz-acl header appropriately. */ public Response copy(String sourceBucket, String sourceKey, String destinationBucket, String destinationKey, Map headers) throws IOException { S3Object object=new S3Object(new byte[]{}, new HashMap()); headers=headers == null? new HashMap() : new HashMap(headers); headers.put("x-amz-copy-source", Collections.singletonList(sourceBucket + "/" + sourceKey)); headers.put("x-amz-metadata-directive", Collections.singletonList("COPY")); return verifyCopy(put(destinationBucket, destinationKey, object, headers)); }
/** * Creates a copy of an existing S3 Object. In this signature, we will replace the * existing metadata. The default access control policy is private; if you want * to override it, please use x-amz-acl in the headers. * @param sourceBucket The name of the bucket where the source object lives. * @param sourceKey The name of the key to copy. * @param destinationBucket The name of the bucket to which the object will be added. * @param destinationKey The name of the key to use. * @param metadata A Map of String to List of Strings representing the S3 metadata * for the new object. * @param headers A Map of String to List of Strings representing the http * headers to pass (can be null). You may wish to set the x-amz-acl header appropriately. */ public Response copy(String sourceBucket, String sourceKey, String destinationBucket, String destinationKey, Map metadata, Map headers) throws IOException { S3Object object=new S3Object(new byte[]{}, metadata); headers=headers == null? new HashMap() : new HashMap(headers); headers.put("x-amz-copy-source", Collections.singletonList(sourceBucket + "/" + sourceKey)); headers.put("x-amz-metadata-directive", Collections.singletonList("REPLACE")); return verifyCopy(put(destinationBucket, destinationKey, object, headers)); }
@Override protected void write(List<PingData> list, String clustername) { String filename=addressToFilename(local_addr); String key=sanitize(clustername) + "/" + sanitize(filename); HttpURLConnection httpConn = null; try { ByteArrayOutputStream out=new ByteArrayOutputStream(4096); write(list, out); byte[] data=out.toByteArray(); S3Object val=new S3Object(data, null); if (usingPreSignedUrls()) { Map headers = new TreeMap(); headers.put("x-amz-acl", Collections.singletonList("public-read")); httpConn = conn.put(pre_signed_put_url, val, headers).connection; } else { Map headers=new TreeMap(); headers.put("Content-Type", Collections.singletonList("text/plain")); httpConn = conn.put(location, key, val, headers).connection; } if(!httpConn.getResponseMessage().equals("OK")) { log.error(Util.getMessage("FailedToWriteFileToS3BucketHTTPResponseCode") + httpConn.getResponseCode() + ")"); } } catch (Exception e) { log.error(Util.getMessage("ErrorMarshallingObject"), e); } }
@Override protected void write(List<PingData> list, String clustername) { String filename=addressToFilename(local_addr); String key=sanitize(clustername) + "/" + sanitize(filename); HttpURLConnection httpConn = null; try { ByteArrayOutputStream out=new ByteArrayOutputStream(4096); write(list, out); byte[] data=out.toByteArray(); S3Object val=new S3Object(data, null); if (usingPreSignedUrls()) { Map headers = new TreeMap(); headers.put("x-amz-acl", Collections.singletonList("public-read")); httpConn = conn.put(pre_signed_put_url, val, headers).connection; } else { Map headers=new TreeMap(); headers.put("Content-Type", Collections.singletonList("text/plain")); httpConn = conn.put(location, key, val, headers).connection; } if(!httpConn.getResponseMessage().equals("OK")) { log.error(Util.getMessage("FailedToWriteFileToS3BucketHTTPResponseCode") + httpConn.getResponseCode() + ")"); } } catch (Exception e) { log.error(Util.getMessage("ErrorMarshallingObject"), e); } }
/** * Creates a copy of an existing S3 Object. In this signature, we will replace the * existing metadata. The default access control policy is private; if you want * to override it, please use x-amz-acl in the headers. * @param sourceBucket The name of the bucket where the source object lives. * @param sourceKey The name of the key to copy. * @param destinationBucket The name of the bucket to which the object will be added. * @param destinationKey The name of the key to use. * @param metadata A Map of String to List of Strings representing the S3 metadata * for the new object. * @param headers A Map of String to List of Strings representing the http * headers to pass (can be null). You may wish to set the x-amz-acl header appropriately. */ public Response copy(String sourceBucket, String sourceKey, String destinationBucket, String destinationKey, Map metadata, Map headers) throws IOException { S3Object object=new S3Object(new byte[]{}, metadata); headers=headers == null? new HashMap() : new HashMap(headers); headers.put("x-amz-copy-source", Collections.singletonList(sourceBucket + "/" + sourceKey)); headers.put("x-amz-metadata-directive", Collections.singletonList("REPLACE")); return verifyCopy(put(destinationBucket, destinationKey, object, headers)); }
/** * Creates a copy of an existing S3 Object. In this signature, we will copy the * existing metadata. The default access control policy is private; if you want * to override it, please use x-amz-acl in the headers. * @param sourceBucket The name of the bucket where the source object lives. * @param sourceKey The name of the key to copy. * @param destinationBucket The name of the bucket to which the object will be added. * @param destinationKey The name of the key to use. * @param headers A Map of String to List of Strings representing the http * headers to pass (can be null). You may wish to set the x-amz-acl header appropriately. */ public Response copy(String sourceBucket, String sourceKey, String destinationBucket, String destinationKey, Map headers) throws IOException { S3Object object=new S3Object(new byte[]{}, new HashMap()); headers=headers == null? new HashMap() : new HashMap(headers); headers.put("x-amz-copy-source", Collections.singletonList(sourceBucket + "/" + sourceKey)); headers.put("x-amz-metadata-directive", Collections.singletonList("COPY")); return verifyCopy(put(destinationBucket, destinationKey, object, headers)); }