JAL-3026-JAL-3063 JAXB unmarshaller fix
[jalview.git] / src / jalview / project / Jalview2XML.java
index 42328b8..47a07a0 100644 (file)
@@ -130,6 +130,7 @@ import java.awt.Color;
 import java.awt.Font;
 import java.awt.Rectangle;
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.File;
@@ -1616,6 +1617,7 @@ public class Jalview2XML
       // using save and then load
       try
       {
+       fileName = fileName.replace('\\', '/');
         System.out.println("Writing jar entry " + fileName);
         JarEntry entry = new JarEntry(fileName);
         jout.putNextEntry(entry);
@@ -1796,6 +1798,7 @@ public class Jalview2XML
   {
     if (jout != null)
     {
+      jarEntryName = jarEntryName.replace('\\','/');
       System.out.println("Writing jar entry " + jarEntryName);
       jout.putNextEntry(new JarEntry(jarEntryName));
       DataOutputStream dout = new DataOutputStream(jout);
@@ -2478,7 +2481,7 @@ public class Jalview2XML
    * @param file
    *          - HTTP URL or filename
    */
-  public AlignFrame loadJalviewAlign(final String file)
+  public AlignFrame loadJalviewAlign(final Object file)
   {
 
     jalview.gui.AlignFrame af = null;
@@ -2522,44 +2525,52 @@ public class Jalview2XML
     return af;
   }
 
-  private jarInputStreamProvider createjarInputStreamProvider(
-          final String file) throws MalformedURLException
-  {
-    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 (_url != null)
-        {
-          return new JarInputStream(_url.openStream());
-        }
-        else
-        {
-          return new JarInputStream(new FileInputStream(file));
-        }
-      }
-
-      @Override
-      public String getFilename()
-      {
-        return file;
-      }
-    };
-  }
+       @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());
+                       byte[] bytes = /** @j2sNative ofile._bytes || */
+                                       null;
+                       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;
+               }
+       }
 
   /**
    * Recover jalview session from a jalview project archive. Caller may
@@ -2597,6 +2608,7 @@ public class Jalview2XML
         for (int i = 0; i < entryCount; i++)
         {
           jarentry = jin.getNextJarEntry();
+          System.out.println("Jalview2XML#loadJalviewAlign: jarentry=" + (jarentry == null ? null : jarentry.getName()));
         }
 
         if (jarentry != null && jarentry.getName().endsWith(".xml"))
@@ -2612,7 +2624,7 @@ public class Jalview2XML
           JAXBElement<JalviewModel> jbe = um
                   .unmarshal(streamReader, JalviewModel.class);
           JalviewModel object = jbe.getValue();
-
+          System.out.println("processing JalviewModel object=" + object);
           /*
           Unmarshaller unmar = new Unmarshaller(object);
           unmar.setValidation(false);
@@ -2959,6 +2971,7 @@ public class Jalview2XML
       do
       {
         entry = jin.getNextJarEntry();
+       System.out.println("Jalview2XML#copyJarEntry: jarentry=" + (entry == null ? null : entry.getName()));
       } while (entry != null && !entry.getName().equals(jarEntryName));
       if (entry != null)
       {
@@ -5796,6 +5809,7 @@ public class Jalview2XML
       do
       {
         entry = jin.getNextJarEntry();
+       System.out.println("Jalview2XML#readJarEntry: jarentry=" + (entry == null ? null : entry.getName()));
       } while (entry != null && !entry.getName().equals(jarEntryName));
 
       if (entry != null)