use of com.formkiq.aws.s3.S3ObjectMetadata in project pravega by pravega.
the class ExtendedS3ChunkStorage method doCreate.
@Override
protected ChunkHandle doCreate(String chunkName) throws ChunkStorageException {
Preconditions.checkState(supportsAppend, "supportsAppend is false.");
try {
if (!client.listObjects(config.getBucket(), getObjectPath(chunkName)).getObjects().isEmpty()) {
throw new ChunkAlreadyExistsException(chunkName, "Chunk already exists");
}
S3ObjectMetadata metadata = new S3ObjectMetadata();
metadata.setContentLength((long) 0);
PutObjectRequest request = new PutObjectRequest(config.getBucket(), getObjectPath(chunkName), null).withObjectMetadata(metadata);
if (config.isUseNoneMatch()) {
request.setIfNoneMatch("*");
}
client.putObject(request);
return ChunkHandle.writeHandle(chunkName);
} catch (Exception e) {
throw convertException(chunkName, "doCreate", e);
}
}
use of com.formkiq.aws.s3.S3ObjectMetadata in project pravega by pravega.
the class ExtendedS3ChunkStorage method doGetInfo.
@Override
protected ChunkInfo doGetInfo(String chunkName) throws ChunkStorageException {
try {
S3ObjectMetadata result = client.getObjectMetadata(config.getBucket(), getObjectPath(chunkName));
ChunkInfo information = ChunkInfo.builder().name(chunkName).length(result.getContentLength()).build();
return information;
} catch (Exception e) {
throw convertException(chunkName, "doGetInfo", e);
}
}
use of com.formkiq.aws.s3.S3ObjectMetadata in project pravega by pravega.
the class ExtendedS3ChunkStorage method doCreateWithContent.
@Override
protected ChunkHandle doCreateWithContent(String chunkName, int length, InputStream data) throws ChunkStorageException {
try {
val objectPath = getObjectPath(chunkName);
S3ObjectMetadata metadata = new S3ObjectMetadata().withContentType("application/octet-stream").withContentLength(length);
val request = new PutObjectRequest(this.config.getBucket(), objectPath, data).withObjectMetadata(metadata);
client.putObject(request);
return ChunkHandle.writeHandle(chunkName);
} catch (Exception e) {
throw convertException(chunkName, "doCreateWithContent", e);
}
}
use of com.formkiq.aws.s3.S3ObjectMetadata in project pravega by pravega.
the class S3Mock method getObjectMetadata.
public S3ObjectMetadata getObjectMetadata(String bucketName, String key) {
String objectName = getObjectName(bucketName, key);
S3ObjectMetadata metadata = new S3ObjectMetadata();
synchronized (this.objects) {
ObjectData od = this.objects.get(objectName);
if (od == null) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
metadata.setContentLength((long) od.content.getLength());
metadata.setLastModified(new Date(System.currentTimeMillis()));
}
return metadata;
}
use of com.formkiq.aws.s3.S3ObjectMetadata in project pravega by pravega.
the class S3Mock method putObject.
public PutObjectResult putObject(PutObjectRequest request) {
// Fix passed in object metadata.
if (request.getObjectMetadata() != null) {
request.setObjectMetadata(new S3ObjectMetadata().withContentType(request.getObjectMetadata().getContentType()).withContentLength(request.getObjectMetadata().getContentLength()));
}
String objectName = getObjectName(request.getBucketName(), request.getKey());
synchronized (this.objects) {
if (this.objects.containsKey(objectName)) {
throw new S3Exception(String.format("Object '%s/%s' exists.", request.getBucketName(), request.getKey()), 0, "PreconditionFailed", "");
}
if (null != request.getObject()) {
try {
val bufferView = new ByteArraySegment(((InputStream) request.getObject()).readAllBytes());
this.objects.put(objectName, new ObjectData(bufferView, request.getAcl()));
} catch (IOException ex) {
throw new S3Exception("Copy error", HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
} else {
this.objects.put(objectName, new ObjectData(BufferView.empty(), request.getAcl()));
}
return new PutObjectResult();
}
}
Aggregations