use of com.emc.object.s3.S3Exception in project pravega by pravega.
the class S3FileSystemImpl method completeMultipartUpload.
@Synchronized
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request) {
Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
if (partMap == null) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
try {
partMap.forEach((index, copyPart) -> {
if (copyPart.getKey() != copyPart.getSourceKey()) {
Path sourcePath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getSourceKey());
Path targetPath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getKey());
try (FileChannel sourceChannel = FileChannel.open(sourcePath, StandardOpenOption.READ);
FileChannel targetChannel = FileChannel.open(targetPath, StandardOpenOption.WRITE)) {
targetChannel.transferFrom(sourceChannel, Files.size(targetPath), copyPart.getSourceRange().getLast() + 1 - copyPart.getSourceRange().getFirst());
targetChannel.close();
AclSize aclMap = this.aclMap.get(copyPart.getKey());
this.aclMap.put(copyPart.getKey(), aclMap.withSize(Files.size(targetPath)));
} catch (IOException e) {
throw new S3Exception("NoSuchKey", 404, "NoSuchKey", "");
}
}
});
} finally {
multipartUploads.remove(request.getKey());
}
return new CompleteMultipartUploadResult();
}
use of com.emc.object.s3.S3Exception in project pravega by pravega.
the class S3FileSystemImpl method listObjects.
@Override
public ListObjectsResult listObjects(String bucketName, String prefix) {
ListObjectsResult result = new ListObjectsResult();
ArrayList<S3Object> list = new ArrayList<>();
Path path = Paths.get(this.baseDir, bucketName, prefix);
try {
if (Files.exists(path)) {
if (Files.isDirectory(path)) {
Files.list(path).forEach(file -> {
addFileAsObjectToList(file, list, bucketName);
});
} else {
addFileAsObjectToList(path, list, bucketName);
}
}
} catch (IOException e) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
result.setObjects(list);
return result;
}
use of com.emc.object.s3.S3Exception in project pravega by pravega.
the class S3FileSystemImpl method copyPart.
@Override
public CopyPartResult copyPart(CopyPartRequest request) {
Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
if (partMap == null) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
partMap.put(request.getPartNumber(), request);
CopyPartResult result = new CopyPartResult();
result.setPartNumber(request.getPartNumber());
result.setETag(request.getUploadId());
return result;
}
use of com.emc.object.s3.S3Exception in project pravega by pravega.
the class S3FileSystemImpl method readObjectStream.
@Override
public InputStream readObjectStream(String bucketName, String key, Range range) {
byte[] bytes = new byte[Math.toIntExact(range.getLast() + 1 - range.getFirst())];
Path path = Paths.get(this.baseDir, bucketName, key);
FileInputStream returnStream;
try {
returnStream = new FileInputStream(path.toFile());
if (range.getFirst() != 0) {
long bytesSkipped = 0;
do {
bytesSkipped += returnStream.skip(range.getFirst());
} while (bytesSkipped < range.getFirst());
}
StreamHelpers.readAll(returnStream, bytes, 0, bytes.length);
return new ByteArrayInputStream(bytes);
} catch (IOException e) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
}
use of com.emc.object.s3.S3Exception in project pravega by pravega.
the class S3FileSystemImpl method putObject.
@Override
public PutObjectResult putObject(PutObjectRequest request) {
if (request.getObjectMetadata() != null) {
request.setObjectMetadata(null);
}
try {
Path path = Paths.get(this.baseDir, request.getBucketName(), request.getKey());
Files.createDirectories(path.getParent());
Files.createFile(path);
} catch (IOException e) {
throw new S3Exception(e.getMessage(), 0, e);
}
PutObjectResult retVal = new PutObjectResult();
if (request.getAcl() != null) {
long size = 0;
if (request.getRange() != null) {
size = request.getRange().getLast() + 1;
}
aclMap.putIfAbsent(request.getKey(), new AclSize(request.getAcl(), size));
}
return retVal;
}
Aggregations