From: jprocter Date: Wed, 12 Nov 2008 16:58:40 +0000 (+0000) Subject: jar inputstream provider enabling multiple jar entries to be unmarshalled without... X-Git-Tag: Release_2_5~412 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cf471c7b9d201ca597af3176975c7f845311d9a7;p=jalview.git jar inputstream provider enabling multiple jar entries to be unmarshalled without closing the input stream --- diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index ca2db7b..7bcea33 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -28,6 +28,7 @@ import javax.swing.*; import org.exolab.castor.xml.*; import jalview.binding.*; import jalview.schemes.*; +import jalview.util.jarInputStreamProvider; /** * DOCUMENT ME! @@ -83,35 +84,20 @@ public class Jalview2XML_V1 * @param file * DOCUMENT ME! */ - public AlignFrame LoadJalviewAlign(final String file) + public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider) { - + final String file = jprovider.getFilename(); jalview.gui.AlignFrame af = null; try { - // UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING - URL url = null; - - if (file.startsWith("http://")) - { - url = new URL(file); - } - JarInputStream jin = null; JarEntry jarentry = null; int entryCount = 1; do { - if (url != null) - { - jin = new JarInputStream(url.openStream()); - } - else - { - jin = new JarInputStream(new FileInputStream(file)); - } + jin = jprovider.getJarInputStream(); for (int i = 0; i < entryCount; i++) { diff --git a/src/jalview/util/jarInputStreamProvider.java b/src/jalview/util/jarInputStreamProvider.java new file mode 100644 index 0000000..6012cfd --- /dev/null +++ b/src/jalview/util/jarInputStreamProvider.java @@ -0,0 +1,23 @@ +package jalview.util; + +import java.io.IOException; +import java.util.jar.JarInputStream; + +/** + * input stream provider interface to be implemented + * by any non-file or URL datasources so that all Jar entries + * can be read from the datasource by repeatedly re-opening the JarInputStream. + * + * 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. + */ +public interface jarInputStreamProvider { + /** + * @return properly initialized jar input stream + */ + JarInputStream getJarInputStream() throws IOException; + /** + * + * @return human readable name for datasource used when reporting any problems with it + */ + String getFilename(); +} \ No newline at end of file