jar inputstream provider enabling multiple jar entries to be unmarshalled without...
authorjprocter <Jim Procter>
Wed, 12 Nov 2008 16:58:40 +0000 (16:58 +0000)
committerjprocter <Jim Procter>
Wed, 12 Nov 2008 16:58:40 +0000 (16:58 +0000)
src/jalview/gui/Jalview2XML_V1.java
src/jalview/util/jarInputStreamProvider.java [new file with mode: 0644]

index ca2db7b..7bcea33 100755 (executable)
@@ -28,6 +28,7 @@ import javax.swing.*;
 import org.exolab.castor.xml.*;\r
 import jalview.binding.*;\r
 import jalview.schemes.*;\r
+import jalview.util.jarInputStreamProvider;\r
 \r
 /**\r
  * DOCUMENT ME!\r
@@ -83,35 +84,20 @@ public class Jalview2XML_V1
    * @param file\r
    *                DOCUMENT ME!\r
    */\r
-  public AlignFrame LoadJalviewAlign(final String file)\r
+  public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)\r
   {\r
-\r
+    final String file  = jprovider.getFilename();\r
     jalview.gui.AlignFrame af = null;\r
 \r
     try\r
     {\r
-      // UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING\r
-      URL url = null;\r
-\r
-      if (file.startsWith("http://"))\r
-      {\r
-        url = new URL(file);\r
-      }\r
-\r
       JarInputStream jin = null;\r
       JarEntry jarentry = null;\r
       int entryCount = 1;\r
 \r
       do\r
       {\r
-        if (url != null)\r
-        {\r
-          jin = new JarInputStream(url.openStream());\r
-        }\r
-        else\r
-        {\r
-          jin = new JarInputStream(new FileInputStream(file));\r
-        }\r
+        jin = jprovider.getJarInputStream();\r
 \r
         for (int i = 0; i < entryCount; i++)\r
         {\r
diff --git a/src/jalview/util/jarInputStreamProvider.java b/src/jalview/util/jarInputStreamProvider.java
new file mode 100644 (file)
index 0000000..6012cfd
--- /dev/null
@@ -0,0 +1,23 @@
+package jalview.util;\r
+\r
+import java.io.IOException;\r
+import java.util.jar.JarInputStream;\r
+\r
+/**\r
+ * input stream provider interface to be implemented\r
+ * by any non-file or URL datasources so that all Jar entries\r
+ * can be read from the datasource by repeatedly re-opening the JarInputStream.\r
+ * \r
+ * This is a workaround necessary because castor's unmarshaller will close the input stream after an unmarshalling session, which normally closes the whole Jar input stream, not just the current JarEntry's stream. \r
+ */\r
+public interface jarInputStreamProvider {\r
+  /**\r
+   * @return properly initialized jar input stream\r
+   */\r
+  JarInputStream getJarInputStream() throws IOException;\r
+  /**\r
+   * \r
+   * @return human readable name for datasource used when reporting any problems with it\r
+   */\r
+  String getFilename();\r
+}
\ No newline at end of file