use of com.emc.object.s3.S3Exception in project pravega by pravega.
the class S3FileSystemImpl method putObject.
@Synchronized
@Override
public void putObject(String bucketName, String key, Range range, Object content) {
Path path = Paths.get(this.baseDir, bucketName, key);
try (FileChannel channel = FileChannel.open(path, StandardOpenOption.WRITE)) {
long startOffset = range.getFirst();
long length = range.getLast() + 1 - range.getFirst();
do {
long bytesTransferred = channel.transferFrom(Channels.newChannel((InputStream) content), range.getFirst(), range.getLast() + 1 - range.getFirst());
length -= bytesTransferred;
startOffset += bytesTransferred;
} while (length > 0);
AclSize aclKey = aclMap.get(key);
aclMap.put(key, aclKey.withSize(range.getLast() + 1));
} catch (IOException e) {
throw new S3Exception("NoObject", 404, "NoSuchKey", key);
}
}
use of com.emc.object.s3.S3Exception in project pravega by pravega.
the class S3FileSystemImpl method getObjectMetadata.
@Override
public S3ObjectMetadata getObjectMetadata(String bucketName, String key) {
S3ObjectMetadata metadata = new S3ObjectMetadata();
AclSize data = aclMap.get(key);
if (data == null) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
metadata.setContentLength(data.getSize());
Path path = Paths.get(this.baseDir, bucketName, key);
metadata.setLastModified(new Date(path.toFile().lastModified()));
return metadata;
}
use of com.emc.object.s3.S3Exception in project pravega by pravega.
the class S3ProxyImpl method putObject.
@Synchronized
@Override
public void putObject(String bucketName, String key, Range range, Object content) {
byte[] totalByes = new byte[Math.toIntExact(range.getLast() + 1)];
try {
if (range.getFirst() != 0) {
int bytesRead = client.getObject(bucketName, key).getObject().read(totalByes, 0, Math.toIntExact(range.getFirst()));
if (bytesRead != range.getFirst()) {
throw new IllegalStateException("Unable to read from the object " + key);
}
}
int bytesRead = ((InputStream) content).read(totalByes, Math.toIntExact(range.getFirst()), Math.toIntExact(range.getLast() + 1 - range.getFirst()));
if (bytesRead != range.getLast() + 1 - range.getFirst()) {
throw new IllegalStateException("Not able to read from input stream.");
}
client.putObject(new PutObjectRequest(bucketName, key, (Object) new ByteArrayInputStream(totalByes)));
aclMap.put(key, aclMap.get(key).withSize(range.getLast() - 1));
} catch (IOException e) {
throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
}
}
Aggregations