X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fproject%2FJalview2XML.java;h=9507a87ef457e934a56a5e369c3559898e9df625;hb=e7921fdc9d6ab87ef91bb7781dd7d9316e671e3f;hp=ccfe460ffb9324c8c09683fde0dee130b7cad57d;hpb=ebdfa53c87bffaf7233f631dd0330d70660c9b5f;p=jalview.git diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index ccfe460..9507a87 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -161,6 +161,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -266,6 +267,25 @@ public class Jalview2XML private Map rnaSessions = new HashMap<>(); /** + * contains last error message (if any) encountered by XML loader. + */ + String errorMessage = null; + + /** + * flag to control whether the Jalview2XML_V1 parser should be deferred to if + * exceptions are raised during project XML parsing + */ + public boolean attemptversion1parse = false; + + /* + * JalviewJS only -- to allow read file bytes to be saved in the + * created AlignFrame, allowing File | Reload of a project file to work + * + * BH 2019 JAL-3436 + */ + private File jarFile; + + /** * A helper method for safely using the value of an optional attribute that * may be null if not present in the XML. Answers the boolean value, or false * if null. @@ -2731,24 +2751,6 @@ public class Jalview2XML } /** - * contains last error message (if any) encountered by XML loader. - */ - String errorMessage = null; - - /** - * flag to control whether the Jalview2XML_V1 parser should be deferred to if - * exceptions are raised during project XML parsing - */ - public boolean attemptversion1parse = false; - - /** - * JalviewJS only -- to preserve bytes in AlignFrame - * - * BH 2019 JAL-3436 - */ - private File file; - - /** * Load a jalview project archive from a jar file * * @param file @@ -2800,55 +2802,50 @@ public class Jalview2XML } @SuppressWarnings("unused") - private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException { - - // BH 2018 allow for bytes already attached to File object - try { - String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString()); + private jarInputStreamProvider createjarInputStreamProvider( + final Object ofile) throws MalformedURLException + { + try + { + String file = (ofile instanceof File + ? ((File) ofile).getCanonicalPath() + : ofile.toString()); byte[] bytes = Platform.isJS() ? Platform.getFileBytes((File) ofile) : null; if (bytes != null) { - this.file = (File) ofile; - } - URL url = null; - errorMessage = null; - uniqueSetSuffix = null; - seqRefIds = null; - viewportsAdded.clear(); - frefedSequence = null; - - if (file.startsWith("http://")) { - url = new URL(file); - } - final URL _url = url; - return new jarInputStreamProvider() { - - @Override - public JarInputStream getJarInputStream() throws IOException { - if (bytes != null) { -// System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length); - return new JarInputStream(new ByteArrayInputStream(bytes)); - } - if (_url != null) { -// System.out.println("Jalview2XML: opening url jarInputStream for " + _url); - return new JarInputStream(_url.openStream()); - } else { -// System.out.println("Jalview2XML: opening file jarInputStream for " + file); - return new JarInputStream(new FileInputStream(file)); - } - } - - @Override - public String getFilename() { - return file; - } - }; - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } + this.jarFile = (File) ofile; + } + errorMessage = null; + uniqueSetSuffix = null; + seqRefIds = null; + viewportsAdded.clear(); + frefedSequence = null; + + URL url = file.startsWith("http://") ? new URL(file) : null; + return new jarInputStreamProvider() + { + @Override + public JarInputStream getJarInputStream() throws IOException + { + InputStream is = bytes != null ? new ByteArrayInputStream(bytes) + : (url != null ? url.openStream() + : new FileInputStream(file)); + return new JarInputStream(is); + } + + @Override + public String getFilename() + { + return file; + } + }; + } catch (IOException e) + { + e.printStackTrace(); + return null; + } + } /** * Recover jalview session from a jalview project archive. Caller may @@ -5029,7 +5026,7 @@ public class Jalview2XML ; af.alignPanel.setHoldRepaint(true); af.setFileName(fileName, FileFormat.Jalview); - af.setFileObject(file); // BH 2019 JAL-3436 + af.setFileObject(jarFile); // BH 2019 JAL-3436 final AlignViewport viewport = af.getViewport(); for (int i = 0; i < JSEQ.size(); i++)