* Avoid FD leaking in binary importer/exporter

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10768 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
sha..RD 11 years ago
parent d6a1b63206
commit f94bc8660c
  1. 10
      engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java
  2. 8
      engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java

@ -327,14 +327,18 @@ public class BinaryExporter implements JmeExporter {
public boolean save(Savable object, File f) throws IOException {
File parentDirectory = f.getParentFile();
if(parentDirectory != null && !parentDirectory.exists()) {
if (parentDirectory != null && !parentDirectory.exists()) {
parentDirectory.mkdirs();
}
FileOutputStream fos = new FileOutputStream(f);
boolean rVal = save(object, fos);
try {
return save(object, fos);
} finally {
if (fos != null) {
fos.close();
return rVal;
}
}
}
public BinaryOutputCapsule getCapsule(Savable object) {

@ -267,9 +267,13 @@ public final class BinaryImporter implements JmeImporter {
public Savable load(File f, ReadListener listener) throws IOException {
FileInputStream fis = new FileInputStream(f);
Savable rVal = load(fis, listener);
try {
return load(fis, listener);
} finally {
if (fis != null) {
fis.close();
return rVal;
}
}
}
public Savable load(byte[] data) throws IOException {

Loading…
Cancel
Save