use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project zeppelin by apache.
the class S3NotebookRepo method save.
@Override
public void save(Note note, AuthenticationInfo subject) throws IOException {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
String json = gson.toJson(note);
String key = user + "/" + "notebook" + "/" + note.getId() + "/" + "note.json";
File file = File.createTempFile("note", "json");
try {
Writer writer = new OutputStreamWriter(new FileOutputStream(file));
writer.write(json);
writer.close();
PutObjectRequest putRequest = new PutObjectRequest(bucketName, key, file);
if (useServerSideEncryption) {
// Request server-side encryption.
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
putRequest.setMetadata(objectMetadata);
}
s3client.putObject(putRequest);
} catch (AmazonClientException ace) {
throw new IOException("Unable to store note in S3: " + ace, ace);
} finally {
FileUtils.deleteQuietly(file);
}
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project YCSB by brianfrankcooper.
the class S3Client method writeToStorage.
/**
* Upload a new object to S3 or update an object on S3.
*
* @param bucket
* The name of the bucket
* @param key
* The file key of the object to upload/update.
* @param values
* The data to be written on the object
* @param updateMarker
* A boolean value. If true a new object will be uploaded
* to S3. If false an existing object will be re-uploaded
*
*/
protected Status writeToStorage(String bucket, String key, HashMap<String, ByteIterator> values, Boolean updateMarker, String sseLocal, SSECustomerKey ssecLocal) {
int totalSize = 0;
//number of fields to concatenate
int fieldCount = values.size();
// getting the first field in the values
Object keyToSearch = values.keySet().toArray()[0];
// getting the content of just one field
byte[] sourceArray = values.get(keyToSearch).toArray();
//size of each array
int sizeArray = sourceArray.length;
if (updateMarker) {
totalSize = sizeArray * fieldCount;
} else {
try {
Map.Entry<S3Object, ObjectMetadata> objectAndMetadata = getS3ObjectAndMetadata(bucket, key, ssecLocal);
int sizeOfFile = (int) objectAndMetadata.getValue().getContentLength();
fieldCount = sizeOfFile / sizeArray;
totalSize = sizeOfFile;
objectAndMetadata.getKey().close();
} catch (Exception e) {
System.err.println("Not possible to get the object :" + key);
e.printStackTrace();
return Status.ERROR;
}
}
byte[] destinationArray = new byte[totalSize];
int offset = 0;
for (int i = 0; i < fieldCount; i++) {
System.arraycopy(sourceArray, 0, destinationArray, offset, sizeArray);
offset += sizeArray;
}
try (InputStream input = new ByteArrayInputStream(destinationArray)) {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(totalSize);
PutObjectRequest putObjectRequest = null;
if (sseLocal.equals("true")) {
metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
putObjectRequest = new PutObjectRequest(bucket, key, input, metadata);
} else if (ssecLocal != null) {
putObjectRequest = new PutObjectRequest(bucket, key, input, metadata).withSSECustomerKey(ssecLocal);
} else {
putObjectRequest = new PutObjectRequest(bucket, key, input, metadata);
}
try {
PutObjectResult res = s3Client.putObject(putObjectRequest);
if (res.getETag() == null) {
return Status.ERROR;
} else {
if (sseLocal.equals("true")) {
System.out.println("Uploaded object encryption status is " + res.getSSEAlgorithm());
} else if (ssecLocal != null) {
System.out.println("Uploaded object encryption status is " + res.getSSEAlgorithm());
}
}
} catch (Exception e) {
System.err.println("Not possible to write object :" + key);
e.printStackTrace();
return Status.ERROR;
}
} catch (Exception e) {
System.err.println("Error in the creation of the stream :" + e.toString());
e.printStackTrace();
return Status.ERROR;
}
return Status.OK;
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project gradle by gradle.
the class S3Resource method getMetaData.
public ExternalResourceMetaData getMetaData() {
ObjectMetadata objectMetadata = s3Object.getObjectMetadata();
Date lastModified = objectMetadata.getLastModified();
return new DefaultExternalResourceMetaData(uri, lastModified.getTime(), getContentLength(), s3Object.getObjectMetadata().getContentType(), s3Object.getObjectMetadata().getETag(), // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb)
null);
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project gradle by gradle.
the class S3ResourceConnector method getMetaData.
public ExternalResourceMetaData getMetaData(URI location, boolean revalidate) {
LOGGER.debug("Attempting to get resource metadata: {}", location);
S3Object s3Object = s3Client.getMetaData(location);
if (s3Object == null) {
return null;
}
try {
ObjectMetadata objectMetadata = s3Object.getObjectMetadata();
return new DefaultExternalResourceMetaData(location, objectMetadata.getLastModified().getTime(), objectMetadata.getContentLength(), objectMetadata.getContentType(), objectMetadata.getETag(), // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb)
null);
} finally {
IoActions.closeQuietly(s3Object);
}
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project airpal by airbnb.
the class S3FilesResource method getFile.
@GET
@Path("/{filename}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getFile(@PathParam("filename") String filename) {
val outputKey = getOutputKey(filename);
val getRequest = new GetObjectRequest(outputBucket, outputKey);
final val object = s3Client.getObject(getRequest);
if (object == null) {
return Response.status(Response.Status.NOT_FOUND).build();
} else {
ObjectMetadata objectMetadata = object.getObjectMetadata();
Response.ResponseBuilder builder = Response.ok().type(objectMetadata.getContentType());
if (objectMetadata.getContentEncoding() != null) {
// gzip
builder = builder.encoding(objectMetadata.getContentEncoding());
}
return builder.entity(new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
try (InputStream objectData = object.getObjectContent()) {
ByteStreams.copy(objectData, output);
} finally {
output.close();
}
}
}).build();
}
}
Aggregations