use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.
the class KMLService method handleSuperOverlay.
/**
* Creates a superoverlay, ie. a short description and network links to the first overlays.
*/
private void handleSuperOverlay(ConveyorKMLTile tile) throws GeoWebCacheException {
TileLayer layer = tile.getLayer();
GridSubset gridSubset = tile.getGridSubset();
// int srsIdx = layer.getSRSIndex(srs);
BoundingBox bbox = gridSubset.getCoverageBestFitBounds();
String formatExtension = "." + tile.getMimeType().getFileExtension();
if (tile.getWrapperMimeType() != null) {
formatExtension = formatExtension + "." + tile.getWrapperMimeType().getFileExtension();
}
long[] gridRect = gridSubset.getCoverageBestFit();
String networkLinks = null;
// Check whether we need two tiles for world bounds or not
if (gridRect[4] > 0 && (gridRect[2] != gridRect[0] || gridRect[3] != gridRect[1])) {
throw new GeoWebCacheException(layer.getName() + " (" + bbox.toString() + ") is too big for the sub grid set for " + gridSubset.getName() + ", allow for smaller zoom levels.");
} else if (gridRect[0] != gridRect[2]) {
long[] gridLocWest = { 0, 0, 0 };
long[] gridLocEast = { 1, 0, 0 };
BoundingBox bboxWest = new BoundingBox(bbox.getMinX(), bbox.getMinY(), 0.0, bbox.getMaxY());
BoundingBox bboxEast = new BoundingBox(0.0, bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY());
networkLinks = superOverlayNetworLink(layer.getName() + " West", bboxWest, tile.getUrlPrefix() + "/" + gridLocString(gridLocWest) + formatExtension) + superOverlayNetworLink(layer.getName() + " East", bboxEast, tile.getUrlPrefix() + "/" + gridLocString(gridLocEast) + formatExtension);
} else {
long[] gridLoc = { gridRect[0], gridRect[1], gridRect[4] };
networkLinks = superOverlayNetworLink(layer.getName(), bbox, tile.getUrlPrefix() + "/" + gridLocString(gridLoc) + formatExtension);
}
String xml = KMLHeader() + "\n<Folder>" + getLookAt(bbox) + networkLinks + "\n</Folder>" + "\n</kml>\n";
tile.setBlob(new ByteArrayResource(xml.getBytes()));
tile.setMimeType(XMLMime.kml);
tile.setStatus(200);
String mimeStr = getMimeTypeOverride(tile);
writeTileResponse(tile, true, stats, mimeStr);
}
use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.
the class KMLService method handleOverlay.
/**
* These are the main nodes in the KML hierarchy, each overlay contains a set of network links
* (up to 4) that point to the overlays on the next level.
*
* <p>1) KMZ: The cache will contain a zip with overlay and data
*
* <p>2) KML: The cache will only contain the overlay itself, the overlay will cause a separate
* tile request to get the data
*/
private void handleOverlay(ConveyorKMLTile tile) throws GeoWebCacheException {
TileLayer tileLayer = tile.getLayer();
boolean packageData = false;
if (tile.getWrapperMimeType() == XMLMime.kmz) {
packageData = true;
}
// Sigh....
if (!packageData) {
String overlayXml = createOverlay(tile, false);
tile.setBlob(new ByteArrayResource(overlayXml.getBytes()));
tile.setStatus(200);
// tileLayer.putTile(tile);
} else {
// Get the overlay
String overlayXml = createOverlay(tile, true);
// Get the data (cheat)
try {
tile.setWrapperMimeType(null);
try {
tileLayer.getTile(tile);
} catch (OutsideCoverageException oce) {
log.error("Out of bounds: " + Arrays.toString(tile.getTileIndex()) + " should never habe been linked to.");
throw oce;
}
tile.setWrapperMimeType(XMLMime.kmz);
} catch (IOException ioe) {
log.error(ioe);
throw new ServiceException(ioe.getMessage());
}
byte[] zip = KMZHelper.createZippedKML(gridLocString(tile.getTileIndex()), tile.getMimeType().getFileExtension(), overlayXml.getBytes(), tile.getBlob());
tile.setBlob(new ByteArrayResource(zip));
tile.setStatus(200);
// tileLayer.putTile(tile);
}
String mimeStr = getMimeTypeOverride(tile);
writeTileResponse(tile, true, stats, mimeStr);
}
use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.
the class S3BlobStore method get.
@Override
public boolean get(TileObject obj) throws StorageException {
final String key = keyBuilder.forTile(obj);
try (S3Object object = s3Ops.getObject(key)) {
if (object == null) {
return false;
}
try (S3ObjectInputStream in = object.getObjectContent()) {
byte[] bytes = ByteStreams.toByteArray(in);
obj.setBlobSize(bytes.length);
obj.setBlob(new ByteArrayResource(bytes));
obj.setCreated(object.getObjectMetadata().getLastModified().getTime());
}
} catch (IOException e) {
throw new StorageException("Error getting " + key, e);
}
return true;
}
use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.
the class HazelcastCacheProviderTest method testTilePut.
@Test
public void testTilePut() throws Exception {
// Clearing cache
cache1.clear();
// Ensure that both caches are cleared
assertEquals(0, cache1.getStatistics().getActualSize());
assertEquals(0, cache2.getStatistics().getActualSize());
// Put a TileObject
Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes());
long[] xyz = { 1L, 2L, 3L };
Map<String, String> parameters = new HashMap<>();
parameters.put("a", "x");
parameters.put("b", "ΓΈ");
TileObject to = TileObject.createCompleteTileObject("test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters, bytes);
mem1.put(to);
// Try to get the same TileObject
TileObject to2 = TileObject.createQueryTileObject("test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters);
assertTrue(mem2.get(to2));
// Checks on the format
assertEquals(to.getBlobFormat(), to2.getBlobFormat());
// Checks if the resources are equals
try (InputStream is = to.getBlob().getInputStream();
InputStream is2 = to2.getBlob().getInputStream()) {
checkInputStreams(is, is2);
}
// Ensure Caches contain the result
TileObject to3 = cache1.getTileObj(to);
assertNotNull(to3);
// Checks if the resources are equals
try (InputStream is = to.getBlob().getInputStream();
InputStream is3 = to3.getBlob().getInputStream()) {
checkInputStreams(is, is3);
}
TileObject to4 = cache2.getTileObj(to);
assertNotNull(to4);
// Checks if the resources are equals
try (InputStream is = to.getBlob().getInputStream();
InputStream is4 = to4.getBlob().getInputStream()) {
checkInputStreams(is, is4);
}
}
use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.
the class AbstractAzureBlobStoreIntegrationTest method testDelete.
@Test
public void testDelete() throws MimeException, StorageException {
byte[] bytes = new byte[1024];
Arrays.fill(bytes, (byte) 0xaf);
TileObject tile = queryTile(20, 30, 12);
tile.setBlob(new ByteArrayResource(bytes));
blobStore.put(tile);
tile.getXYZ()[0] = 21;
blobStore.put(tile);
tile.getXYZ()[0] = 22;
blobStore.put(tile);
tile = queryTile(20, 30, 12);
assertTrue(blobStore.delete(tile));
tile.getXYZ()[0] = 21;
assertTrue(blobStore.delete(tile));
BlobStoreListener listener = mock(BlobStoreListener.class);
blobStore.addListener(listener);
tile.getXYZ()[0] = 22;
assertTrue(blobStore.delete(tile));
assertFalse(blobStore.delete(tile));
verify(listener, times(1)).tileDeleted(eq(tile.getLayerName()), eq(tile.getGridSetId()), eq(tile.getBlobFormat()), anyString(), eq(22L), eq(30L), eq(12), eq(1024L));
}
Aggregations