Search in sources :

Example 1 with BlobStoreException

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);
    }
}
Also used : S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) BlobStoreException(com.baremaps.blob.BlobStoreException) RequestBody(software.amazon.awssdk.core.sync.RequestBody)

Example 2 with BlobStoreException

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);
    }
}
Also used : DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) BlobStoreException(com.baremaps.blob.BlobStoreException)

Example 3 with BlobStoreException

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);
    }
}
Also used : GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) BlobStoreException(com.baremaps.blob.BlobStoreException)

Example 4 with BlobStoreException

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);
    }
}
Also used : HeadObjectResponse(software.amazon.awssdk.services.s3.model.HeadObjectResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) HeadObjectRequest(software.amazon.awssdk.services.s3.model.HeadObjectRequest) BlobStoreException(com.baremaps.blob.BlobStoreException)

Example 5 with BlobStoreException

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...
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) URI(java.net.URI) BlobStore(com.baremaps.blob.BlobStore) BlobStoreException(com.baremaps.blob.BlobStoreException) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

BlobStoreException (com.baremaps.blob.BlobStoreException)6 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)4 BlobStore (com.baremaps.blob.BlobStore)2 InputStreamReader (java.io.InputStreamReader)2 URI (java.net.URI)2 Query (com.baremaps.model.Query)1 TileJSON (com.baremaps.model.TileJSON)1 StreamProgress (com.baremaps.osm.progress.StreamProgress)1 PostgresUtils (com.baremaps.postgres.jdbc.PostgresUtils)1 DefaultObjectMapper.defaultObjectMapper (com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper)1 Conversions.asPostgresQuery (com.baremaps.server.ogcapi.Conversions.asPostgresQuery)1 StreamUtils (com.baremaps.stream.StreamUtils)1 Tile (com.baremaps.tile.Tile)1 TileBatchPredicate (com.baremaps.tile.TileBatchPredicate)1 TileBlobStore (com.baremaps.tile.TileBlobStore)1 TileChannel (com.baremaps.tile.TileChannel)1 TileStore (com.baremaps.tile.TileStore)1 TileStoreException (com.baremaps.tile.TileStoreException)1 MBTiles (com.baremaps.tile.mbtiles.MBTiles)1 PostgresQuery (com.baremaps.tile.postgres.PostgresQuery)1