use of com.baremaps.blob.Blob in project baremaps by baremaps.
the class EditorResources method getTile.
@GET
@javax.ws.rs.Path("/tiles/{z}/{x}/{y}.mvt")
public Response getTile(@PathParam("z") int z, @PathParam("x") int x, @PathParam("y") int y) {
try {
List<PostgresQuery> queries = asPostgresQuery(getTileset());
TileStore tileStore = new PostgresTileStore(dataSource, queries);
Tile tile = new Tile(x, y, z);
Blob blob = tileStore.read(tile);
if (blob != null) {
return Response.status(200).header(CONTENT_TYPE, blob.getContentType()).header(CONTENT_ENCODING, blob.getContentEncoding()).entity(blob.getInputStream()).build();
} else {
return Response.status(204).build();
}
} catch (Exception ex) {
logger.error("Tile error", ex);
return Response.status(404).build();
}
}
use of com.baremaps.blob.Blob in project baremaps by baremaps.
the class UpdateService method call.
@Override
public Void call() throws Exception {
Header header = headerRepository.selectLatest();
String replicationUrl = header.getReplicationUrl();
Long sequenceNumber = header.getReplicationSequenceNumber() + 1;
Consumer<Entity> createGeometry = new CreateGeometryConsumer(coordinates, references);
Consumer<Entity> reprojectGeometry = new ReprojectEntityConsumer(4326, srid);
Consumer<Change> prepareGeometries = new ChangeEntityConsumer(createGeometry.andThen(reprojectGeometry));
Function<Change, Change> prepareChange = consumeThenReturn(prepareGeometries);
Consumer<Change> saveChange = new SaveChangeConsumer(nodeRepository, wayRepository, relationRepository);
URI changeUri = resolve(replicationUrl, sequenceNumber, "osc.gz");
Blob changeBlob = blobStore.get(changeUri);
ProgressLogger progressLogger = new ProgressLogger(changeBlob.getContentLength(), 5000);
try (InputStream blobInputStream = changeBlob.getInputStream();
InputStream progressInputStream = new InputStreamProgress(blobInputStream, progressLogger);
InputStream gzipInputStream = new GZIPInputStream(progressInputStream)) {
new OsmChangeParser().changes(gzipInputStream).map(prepareChange).forEach(saveChange);
}
URI stateUri = resolve(replicationUrl, sequenceNumber, "state.txt");
Blob stateBlob = blobStore.get(stateUri);
try (InputStream stateInputStream = stateBlob.getInputStream()) {
State state = new OsmStateParser().state(stateInputStream);
headerRepository.put(new Header(state.getSequenceNumber(), state.getTimestamp(), header.getReplicationUrl(), header.getSource(), header.getWritingProgram()));
}
return null;
}
use of com.baremaps.blob.Blob in project baremaps by baremaps.
the class JavaScriptConfig method read.
/**
* {@inheritDoc} *
*/
@Override
public byte[] read() throws ConfigException {
try {
Blob blob = store.get(uri);
try (Reader reader = new InputStreamReader(blob.getInputStream())) {
Source source = Source.newBuilder("js", reader, "config.js").mimeType("application/javascript+module").build();
Value value = context.eval(source);
return value.getMember("default").toString().getBytes(StandardCharsets.UTF_8);
}
} catch (Exception e) {
throw new ConfigException(e);
}
}
use of com.baremaps.blob.Blob in project baremaps by baremaps.
the class TileStoreTest method readWriteDeleteTile.
@Test
@Tag("integration")
void readWriteDeleteTile() throws Exception {
TileStore tileStore = createTileStore();
Tile tile = new Tile(1, 2, 3);
byte[] bytes = "tile_content".getBytes();
Blob blob = Blob.builder().withByteArray(bytes).build();
// Write data
tileStore.write(tile, blob);
// Read the data
try (InputStream inputStream = tileStore.read(tile).getInputStream()) {
assertArrayEquals(bytes, inputStream.readAllBytes());
}
// Delete the data
tileStore.delete(tile);
assertThrows(TileStoreException.class, () -> tileStore.read(tile));
}
use of com.baremaps.blob.Blob in project baremaps by baremaps.
the class TileStoreTest method readWriteDeleteTile.
// TODO: try to move this in the testing module
@Test
@Tag("integration")
void readWriteDeleteTile() throws Exception {
TileStore tileStore = createTileStore();
Tile tile = new Tile(1, 2, 3);
byte[] bytes = "tile_content".getBytes();
Blob blob = Blob.builder().withByteArray(bytes).build();
// Write data
tileStore.write(tile, blob);
// Read the data
try (InputStream inputStream = tileStore.read(tile).getInputStream()) {
assertArrayEquals(bytes, inputStream.readAllBytes());
}
// Delete the data
tileStore.delete(tile);
assertThrows(TileStoreException.class, () -> tileStore.read(tile));
}
Aggregations