Changeset 30427 in osm for applications/viewer/jmapviewer
- Timestamp:
- 2014-04-29T18:05:28+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r30426 r30427 261 261 262 262 protected boolean loadTileFromFile() { 263 FileInputStream fin = null;264 263 try { 265 264 tileFile = getTileFile(); … … 268 267 269 268 loadTagsFromFile(); 270 if ("no-tile".equals(tile.getValue("tile-info"))) 271 { 269 if ("no-tile".equals(tile.getValue("tile-info"))) { 272 270 tile.setError("No tile at this zoom level"); 273 271 if (tileFile.exists()) { … … 276 274 tileFile = getTagsFile(); 277 275 } else { 278 fin = new FileInputStream(tileFile); 279 try { 276 try (FileInputStream fin = new FileInputStream(tileFile)) { 280 277 if (fin.available() == 0) 281 278 throw new IOException("File empty"); 282 279 tile.loadImage(fin); 283 } finally {284 fin.close();285 280 } 286 281 } … … 297 292 fileTilePainted = true; 298 293 } catch (Exception e) { 299 try { 300 if (fin != null) { 301 fin.close(); 302 tileFile.delete(); 303 } 304 } catch (Exception e1) { 305 } 294 tileFile.delete(); 306 295 tileFile = null; 307 296 fileAge = 0; … … 392 381 393 382 protected void saveTileToFile(byte[] rawData) { 394 try {383 try ( 395 384 FileOutputStream f = new FileOutputStream(tileCacheDir + "/" + tile.getZoom() + "_" + tile.getXtile() 396 + "_" + tile.getYtile() + "." + tile.getSource().getTileType()); 385 + "_" + tile.getYtile() + "." + tile.getSource().getTileType()) 386 ) { 397 387 f.write(rawData); 398 f.close();399 // System.out.println("Saved tile to file: " + tile);400 388 } catch (Exception e) { 401 389 System.err.println("Failed to save tile content: " + e.getLocalizedMessage()); … … 409 397 return; 410 398 } 411 try { 412 final PrintWriter f = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tagsFile), 413 TAGS_CHARSET)); 399 try (PrintWriter f = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tagsFile), TAGS_CHARSET))) { 414 400 for (Entry<String, String> entry : tile.getMetadata().entrySet()) { 415 401 f.println(entry.getKey() + "=" + entry.getValue()); 416 402 } 417 f.close();418 403 } catch (Exception e) { 419 404 System.err.println("Failed to save tile tags: " + e.getLocalizedMessage()); … … 426 411 + tile.getXtile() + "_" + tile.getYtile() + ETAG_FILE_EXT); 427 412 if (!etagFile.exists()) return; 428 try { 429 FileInputStream f = new FileInputStream(etagFile); 413 try (FileInputStream f = new FileInputStream(etagFile)) { 430 414 byte[] buf = new byte[f.available()]; 431 415 f.read(buf); … … 444 428 loadOldETagfromFile(); 445 429 File tagsFile = getTagsFile(); 446 try { 447 final BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(tagsFile), 448 TAGS_CHARSET)); 430 try (BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(tagsFile), TAGS_CHARSET))) { 449 431 for (String line = f.readLine(); line != null; line = f.readLine()) { 450 432 final int i = line.indexOf('='); … … 455 437 tile.putValue(line.substring(0,i),line.substring(i+1)); 456 438 } 457 f.close();458 439 } catch (FileNotFoundException e) { 459 440 } catch (Exception e) { … … 461 442 } 462 443 } 463 464 444 } 465 445
Note:
See TracChangeset
for help on using the changeset viewer.