comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 623:65f09139e9b3

Fixed file handle leak when writing meta data. gnv-artifacts/trunk@694 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 21 Feb 2010 21:05:55 +0000
parents 89aca25642d6
children 8d2bd52f05e3
comparison
equal deleted inserted replaced
622:89aca25642d6 623:65f09139e9b3
381 if (!metaFile.createNewFile() || !metaFile.canWrite()) { 381 if (!metaFile.createNewFile() || !metaFile.canWrite()) {
382 log.error("Error while writing meta file: "+metaFile.toString()); 382 log.error("Error while writing meta file: "+metaFile.toString());
383 return null; 383 return null;
384 } 384 }
385 385
386 OutputStream out = new FileOutputStream(metaFile); 386 OutputStream out = null;
387 XMLUtils.toStream(meta, out); 387 boolean success = false;
388 388 try {
389 return meta; 389 out = new FileOutputStream(metaFile);
390 success = XMLUtils.toStream(meta, out);
391 }
392 finally {
393 if (out != null) {
394 try { out.close(); }
395 catch (IOException ioe) {}
396 }
397 }
398
399 if (!success && metaFile.exists()) {
400 metaFile.delete();
401 }
402
403 return success ? meta : null;
390 } 404 }
391 catch (FileNotFoundException fnfe) { 405 catch (FileNotFoundException fnfe) {
392 log.error(fnfe); 406 log.error(fnfe);
393 } 407 }
394 catch (IOException ioe) { 408 catch (IOException ioe) {

http://dive4elements.wald.intevation.org