use of com.baremaps.blob.BlobStoreException in project baremaps by baremaps.
the class S3BlobStore method put.
/**
* {@inheritDoc}
*/
@Override
public void put(URI uri, Blob blob) throws BlobStoreException {
try {
PutObjectRequest.Builder builder = PutObjectRequest.builder().bucket(uri.getHost()).key(uri.getPath().substring(1)).contentLength(blob.getContentLength()).contentType(blob.getContentType()).contentEncoding(blob.getContentEncoding());
RequestBody requestBody = RequestBody.fromInputStream(blob.getInputStream(), blob.getContentLength());
client.putObject(builder.build(), requestBody);
} catch (S3Exception e) {
throw new BlobStoreException(e);
}
}
use of com.baremaps.blob.BlobStoreException in project baremaps by baremaps.
the class S3BlobStore method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(URI uri) throws BlobStoreException {
try {
DeleteObjectRequest request = DeleteObjectRequest.builder().bucket(uri.getHost()).key(uri.getPath().substring(1)).build();
client.deleteObject(request);
} catch (S3Exception e) {
throw new BlobStoreException(e);
}
}
use of com.baremaps.blob.BlobStoreException in project baremaps by baremaps.
the class S3BlobStore method get.
/**
* {@inheritDoc}
*/
@Override
public Blob get(URI uri) throws BlobStoreException {
try {
GetObjectRequest request = GetObjectRequest.builder().bucket(uri.getHost()).key(uri.getPath().substring(1)).build();
ResponseInputStream<GetObjectResponse> responseInputStream = client.getObject(request);
GetObjectResponse getObjectResponse = responseInputStream.response();
return Blob.builder().withContentLength(getObjectResponse.contentLength()).withContentType(getObjectResponse.contentType()).withContentEncoding(getObjectResponse.contentEncoding()).withInputStream(responseInputStream).build();
} catch (S3Exception e) {
throw new BlobStoreException(e);
}
}
use of com.baremaps.blob.BlobStoreException in project baremaps by baremaps.
the class S3BlobStore method head.
/**
* {@inheritDoc}
*/
@Override
public Blob head(URI uri) throws BlobStoreException {
try {
HeadObjectRequest request = HeadObjectRequest.builder().bucket(uri.getHost()).key(uri.getPath().substring(1)).build();
HeadObjectResponse response = client.headObject(request);
return Blob.builder().withContentLength(response.contentLength()).withContentType(response.contentType()).withContentEncoding(response.contentEncoding()).build();
} catch (S3Exception e) {
throw new BlobStoreException(e);
}
}
use of com.baremaps.blob.BlobStoreException in project baremaps by baremaps.
the class S3BlobStoreTest method readWriteDelete.
@Test
@Tag("integration")
void readWriteDelete() throws IOException, BlobStoreException {
URI uri = URI.create("s3://test/test/test.txt");
String content = "content";
BlobStore blobStore = new S3BlobStore(s3Client);
// Write data
blobStore.put(uri, Blob.builder().withByteArray(content.getBytes(Charsets.UTF_8)).build());
// Read the data
try (InputStream inputStream = blobStore.get(uri).getInputStream()) {
assertEquals(content, CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8)));
}
// Delete the data
blobStore.delete(uri);
// Get unexisting blob
try (InputStream ignored = blobStore.get(uri).getInputStream()) {
fail("Expected an IOException to be thrown");
} catch (BlobStoreException e) {
// Test exception message...
}
}
Aggregations