@Override public synchronized TileBitmap get(Job key) { File file = this.findFile(key); if (file == null) { return null; } InputStream inputStream = null; try { inputStream = new FileInputStream(file); return this.graphicFactory.createTileBitmap(inputStream, key.tile.tileSize, key.hasAlpha); } catch (CorruptedInputStreamException e) { // this can happen, at least on Android, when the input stream // is somehow corrupted, returning null ensures it will be loaded // from another source return null; } catch (IOException e) { return null; } finally { IOUtils.closeQuietly(inputStream); } }
/** * Draws a bitmap just with outside colour, used for bitmaps outside of map area. * * @param renderContext the RenderContext * @return bitmap drawn in single colour. */ private TileBitmap createBackgroundBitmap(RenderContext renderContext) { TileBitmap bitmap = this.graphicFactory.createTileBitmap(renderContext.rendererJob.tile.tileSize, renderContext.rendererJob.hasAlpha); renderContext.canvasRasterer.setCanvasBitmap(bitmap); if (!renderContext.rendererJob.hasAlpha) { renderContext.canvasRasterer.fill(renderContext.renderTheme.getMapBackgroundOutside()); } return bitmap; }
try { inputStream = new FileInputStream(file); TileBitmap result = this.graphicFactory.createTileBitmap(inputStream, key.tile.tileSize, key.hasAlpha); result.setTimestamp(file.lastModified()); return result;
TileBitmap result = this.graphicFactory.createTileBitmap(inputStream, this.downloadJob.tile.tileSize, this.downloadJob.hasAlpha); result.setExpiration(urlConnection.getExpiration());
@Test public void existingFilesTest() throws IOException { for (int tileSize : TILE_SIZES) { Assert.assertTrue(this.cacheDirectory.mkdirs()); File file1 = new File(this.cacheDirectory, 1 + FileSystemTileCache.FILE_EXTENSION); File file2 = new File(this.cacheDirectory, 2 + FileSystemTileCache.FILE_EXTENSION); Assert.assertTrue(file1.createNewFile()); Assert.assertTrue(file2.createNewFile()); FileSystemTileCache tileCache = new FileSystemTileCache(1, this.cacheDirectory, GRAPHIC_FACTORY); Assert.assertEquals(2, this.cacheDirectory.list().length); Tile tile = new Tile(0, 0, (byte) 0, tileSize); TileSource tileSource = OpenStreetMapMapnik.INSTANCE; Job job = new DownloadJob(tile, tileSource); TileBitmap bitmap = GRAPHIC_FACTORY.createTileBitmap(tileSize, false); tileCache.put(job, bitmap); Assert.assertEquals(3, this.cacheDirectory.list().length); Assert.assertTrue(file1.exists()); Assert.assertTrue(file2.exists()); tileCache.destroy(); Assert.assertFalse(this.cacheDirectory.exists()); } }
@Test public void putTest() { for (int tileSize : TILE_SIZES) { TileCache tileCache = new InMemoryTileCache(0); verifyInvalidPut(tileCache, null, GRAPHIC_FACTORY.createTileBitmap(tileSize, true)); verifyInvalidPut(tileCache, new DownloadJob(new Tile(0, 0, (byte) 0, tileSize), OpenStreetMapMapnik.INSTANCE), null); } }
@Test public void invalidPutTest() { for (int tileSize : TILE_SIZES) { TileCache tileCache = new FileSystemTileCache(1, this.cacheDirectory, GRAPHIC_FACTORY); verifyInvalidPut(tileCache, null, GRAPHIC_FACTORY.createTileBitmap(tileSize, false)); verifyInvalidPut(tileCache, new DownloadJob(new Tile(0, 0, (byte) 0, tileSize), OpenStreetMapMapnik.INSTANCE), null); } }
@Test public void capacityZeroTest() { for (int tileSize : TILE_SIZES) { TileCache tileCache = new FileSystemTileCache(0, this.cacheDirectory, GRAPHIC_FACTORY); Tile tile = new Tile(0, 0, (byte) 0, tileSize); TileSource tileSource = OpenStreetMapMapnik.INSTANCE; Job job = new DownloadJob(tile, tileSource); TileBitmap bitmap = GRAPHIC_FACTORY.createTileBitmap(tileSize, false); tileCache.put(job, bitmap); Assert.assertEquals(0, this.cacheDirectory.list().length); Assert.assertFalse(tileCache.containsKey(job)); Assert.assertNull(tileCache.get(job)); tileCache.destroy(); } }
bitmap = this.graphicFactory.createTileBitmap(rendererJob.tile.tileSize, rendererJob.hasAlpha); bitmap.setTimestamp(rendererJob.mapDataStore.getDataTimestamp(rendererJob.tile)); renderContext.canvasRasterer.setCanvasBitmap(bitmap);
bitmap = this.graphicFactory.createTileBitmap(rendererJob.tile.tileSize, rendererJob.hasAlpha); bitmap.setTimestamp(rendererJob.mapDataStore.getDataTimestamp(rendererJob.tile)); renderContext.canvasRasterer.setCanvasBitmap(bitmap);
Job job1 = new DownloadJob(tile1, tileSource); TileBitmap bitmap1 = GRAPHIC_FACTORY.createTileBitmap(tileSize, true); inMemoryTileCache.put(job1, bitmap1); Assert.assertFalse(inMemoryTileCache.containsKey(job1)); Job job2 = new DownloadJob(tile2, tileSource); inMemoryTileCache.put(job2, GRAPHIC_FACTORY.createTileBitmap(tileSize, true)); Assert.assertFalse(inMemoryTileCache.containsKey(job1)); Assert.assertTrue(inMemoryTileCache.containsKey(job2));
@Override public synchronized TileBitmap get(Job key) { File file = this.findFile(key); if (file == null) { return null; } InputStream inputStream = null; try { inputStream = new FileInputStream(file); return this.graphicFactory.createTileBitmap(inputStream, key.tile.tileSize, key.hasAlpha); } catch (CorruptedInputStreamException e) { // this can happen, at least on Android, when the input stream // is somehow corrupted, returning null ensures it will be loaded // from another source return null; } catch (IOException e) { return null; } finally { IOUtils.closeQuietly(inputStream); } }
/** * Draws a bitmap just with outside colour, used for bitmaps outside of map area. * * @param renderContext the RenderContext * @return bitmap drawn in single colour. */ private TileBitmap createBackgroundBitmap(RenderContext renderContext) { TileBitmap bitmap = this.graphicFactory.createTileBitmap(renderContext.rendererJob.tile.tileSize, renderContext.rendererJob.hasAlpha); renderContext.canvasRasterer.setCanvasBitmap(bitmap); if (!renderContext.rendererJob.hasAlpha) { renderContext.canvasRasterer.fill(renderContext.renderTheme.getMapBackgroundOutside()); } return bitmap; }
try { inputStream = new FileInputStream(file); TileBitmap result = this.graphicFactory.createTileBitmap(inputStream, key.tile.tileSize, key.hasAlpha); result.setTimestamp(file.lastModified()); return result;
tile[i] = new Tile(i, 0, (byte) 4, tileSize); job[i] = new DownloadJob(tile[i], tileSource); bitmap[i] = GRAPHIC_FACTORY.createTileBitmap(tileSize, false);
Assert.assertNull(tileCache.get(job2)); TileBitmap bitmap1 = GRAPHIC_FACTORY.createTileBitmap(tileSize, true); tileCache.put(job1, bitmap1); Assert.assertTrue(tileCache.containsKey(job1)); Assert.assertNull(tileCache.get(job2)); TileBitmap bitmap2 = GRAPHIC_FACTORY.createTileBitmap(tileSize, true); tileCache.put(job2, bitmap2); Assert.assertFalse(tileCache.containsKey(job1));
TileBitmap result = this.graphicFactory.createTileBitmap(inputStream, this.downloadJob.tile.tileSize, this.downloadJob.hasAlpha); result.setExpiration(urlConnection.getExpiration());
Assert.assertNull(tileCache2.get(job3)); TileBitmap bitmap1 = GRAPHIC_FACTORY.createTileBitmap(tileSize, false); tileCache1.put(job1, bitmap1); Assert.assertNull(tileCache2.get(job3)); TileBitmap bitmap2 = GRAPHIC_FACTORY.createTileBitmap(tileSize, false); tileCache2.put(job2, bitmap2); Assert.assertNull(tileCache2.get(job3)); TileBitmap bitmap3 = GRAPHIC_FACTORY.createTileBitmap(tileSize, false); tileCache1.put(job3, bitmap3); Assert.assertFalse(tileCache1.containsKey(job1));
Assert.assertFalse(twoLevelTileCache.containsKey(job)); TileBitmap bitmap = GRAPHIC_FACTORY.createTileBitmap(tileSize, false); twoLevelTileCache.put(job, bitmap);
bitmap = this.graphicFactory.createTileBitmap(rendererJob.tile.tileSize, rendererJob.hasAlpha); bitmap.setTimestamp(rendererJob.mapDataStore.getDataTimestamp(rendererJob.tile)); renderContext.canvasRasterer.setCanvasBitmap(bitmap);