* Avoid FD leaking in AbstractHeightMap save
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10769 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
f94bc8660c
commit
d048d5d6c1
@ -253,9 +253,12 @@ public abstract class AbstractHeightMap implements HeightMap {
|
||||
throw new Exception("Filename must not be null");
|
||||
}
|
||||
//open the streams and send the height data to the file.
|
||||
FileOutputStream fos = null;
|
||||
DataOutputStream dos = null;
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(filename);
|
||||
DataOutputStream dos = new DataOutputStream(fos);
|
||||
fos = new FileOutputStream(filename);
|
||||
dos = new DataOutputStream(fos);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
for (int j = 0; j < size; j++) {
|
||||
dos.write((int) heightData[j + (i * size)]);
|
||||
@ -270,6 +273,13 @@ public abstract class AbstractHeightMap implements HeightMap {
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.WARNING, "Error writing to file {0}", filename);
|
||||
return false;
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
if (dos != null) {
|
||||
dos.close();
|
||||
}
|
||||
}
|
||||
|
||||
logger.log(Level.FINE, "Saved terrain to {0}", filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user