File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
main/groovy/geoscript/layer
test/groovy/geoscript/layer Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -184,5 +184,18 @@ abstract class TileLayer<T extends Tile> implements Closeable {
184
184
String toString () {
185
185
this . name
186
186
}
187
+
188
+ /**
189
+ * Use a TileLayer within a Closure and make sure it gets closed.
190
+ * @param tileLayer The TileLayer
191
+ * @param closure A Closure that takes the TileLayer
192
+ */
193
+ static void withTileLayer (TileLayer tileLayer , Closure closure ) {
194
+ try {
195
+ closure. call(tileLayer)
196
+ } finally {
197
+ tileLayer. close()
198
+ }
199
+ }
187
200
188
201
}
Original file line number Diff line number Diff line change @@ -277,4 +277,16 @@ class TileLayerTestCase {
277
277
}
278
278
}
279
279
280
+ @Test
281
+ void withTileLayer () {
282
+ File file = new File (getClass(). getClassLoader(). getResource(" states.mbtiles" ). toURI())
283
+ TileLayer . withTileLayer(new MBTiles (file)) { TileLayer layer ->
284
+ Tile tile = layer. get(4 , 2 , 3 )
285
+ assertNotNull tile
286
+ assertEquals 4 , tile. z
287
+ assertEquals 2 , tile. x
288
+ assertEquals 3 , tile. y
289
+ assertNotNull tile. data
290
+ }
291
+ }
280
292
}
You can’t perform that action at this time.
0 commit comments