X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Futil%2FOpenFileWorker.java;h=e0c3a8de714ec05ac2986253e1f190cbca1ba0ee;hb=6afc62224f6f7e581b1d321e125ed97a6ec77dc1;hp=2969ae7871ce9e167379f9055fa067ebe4a8d3da;hpb=6930dda4b30229cfc3b34f51561e323fd4f9936b;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/util/OpenFileWorker.java b/src/net/sf/openrocket/util/OpenFileWorker.java index 2969ae78..e0c3a8de 100644 --- a/src/net/sf/openrocket/util/OpenFileWorker.java +++ b/src/net/sf/openrocket/util/OpenFileWorker.java @@ -25,16 +25,39 @@ public class OpenFileWorker extends SwingWorker { private static final RocketLoader ROCKET_LOADER = new GeneralRocketLoader(); private final File file; + private final InputStream stream; public OpenFileWorker(File file) { this.file = file; + this.stream = null; + } + + + public OpenFileWorker(InputStream stream) { + this.stream = stream; + this.file = null; } @Override protected OpenRocketDocument doInBackground() throws Exception { - ProgressInputStream is = new ProgressInputStream( - new BufferedInputStream(new FileInputStream(file))); + InputStream is; + + // Get the correct input stream + if (file != null) { + is = new FileInputStream(file); + } else { + is = stream; + } + + // Buffer stream unless already buffered + if (!(is instanceof BufferedInputStream)) { + is = new BufferedInputStream(is); + } + + // Encapsulate in a ProgressInputStream + is = new ProgressInputStream(is); + try { return ROCKET_LOADER.load(is); } finally { @@ -65,7 +88,7 @@ public class OpenFileWorker extends SwingWorker { System.err.println("ERROR estimating available bytes!"); s = 0; } - size = s; + size = Math.max(s, 1); }