Browse Source

Use BufferedOutputStream

Toni Helenius 4 years ago
parent
commit
2de3f1925b

+ 5 - 4
jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/AddToProjectAction.java

@@ -18,7 +18,7 @@ import javax.swing.Action;
 import org.openide.nodes.Node;
 import org.openide.util.Exceptions;
 import org.w3c.dom.Element;
-import com.jme3.gde.scenecomposer.SceneComposerTopComponent;
+import java.io.BufferedOutputStream;
 import java.io.OutputStream;
 import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
@@ -54,9 +54,10 @@ public final class AddToProjectAction implements Action {
                         }
                         if (modelFolder.isFolder()) {
                             AssetPackLoader.addModelFiles(pm, mgr, conf);
-                            OutputStream out = modelFolder.createAndOpen(conf.getAssetElement().getAttribute("name") + ".j3o");
-                            BinaryExporter.getInstance().save(model, out);
-                            out.close();
+                            try (OutputStream out = modelFolder.createAndOpen(conf.getAssetElement().getAttribute("name") + ".j3o");
+                                    BufferedOutputStream bout = new BufferedOutputStream(out)) {
+                                BinaryExporter.getInstance().save(model, bout);
+                            }
                             modelFolder.refresh();
                         } else {
                             Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot copy, file 'Models' exists");

+ 10 - 7
jme3-core/src/com/jme3/gde/core/assets/AssetDataObject.java

@@ -1,22 +1,22 @@
 /*
  *  Copyright (c) 2009-2010 jMonkeyEngine
  *  All rights reserved.
- * 
+ *
  *  Redistribution and use in source and binary forms, with or without
  *  modification, are permitted provided that the following conditions are
  *  met:
- * 
+ *
  *  * Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
- * 
+ *
  *  * Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  *  * Neither the name of 'jMonkeyEngine' nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
- * 
+ *
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -36,6 +36,7 @@ import com.jme3.asset.AssetKey;
 import com.jme3.export.Savable;
 import com.jme3.export.binary.BinaryExporter;
 import com.jme3.gde.core.scene.SceneApplication;
+import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.reflect.InvocationTargetException;
@@ -231,7 +232,9 @@ public class AssetDataObject extends MultiDataObject {
                 out = outFileObject.getOutputStream();
                 outFileObject.getParent().refresh();
             }
-            exp.save(savable, out);
+            try (BufferedOutputStream bout = new BufferedOutputStream(out)) {
+                exp.save(savable, bout);
+            }
         } finally {
 //            if (lock != null) {
 //                lock.releaseLock();
@@ -239,7 +242,7 @@ public class AssetDataObject extends MultiDataObject {
             if (out != null) {
                 out.close();
             }
-            
+
             progressHandle.finish();
             setModified(false);
         }