*/
package jalview.ws.sifts;
-import jalview.analysis.AlignSeq;
-import jalview.analysis.scoremodels.ScoreMatrix;
-import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.DBRefEntryI;
-import jalview.api.SiftsClientI;
-import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
-import jalview.datamodel.SequenceI;
-import jalview.io.StructureFile;
-import jalview.schemes.ResidueProperties;
-import jalview.structure.StructureMapping;
-import jalview.util.Comparison;
-import jalview.util.DBRefUtils;
-import jalview.util.Format;
-import jalview.xml.binding.sifts.Entry;
-import jalview.xml.binding.sifts.Entry.Entity;
-import jalview.xml.binding.sifts.Entry.Entity.Segment;
-import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
-import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
-import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
-import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.GZIPInputStream;
import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
+import jalview.analysis.AlignSeq;
+import jalview.analysis.scoremodels.ScoreMatrix;
+import jalview.analysis.scoremodels.ScoreModels;
+import jalview.api.DBRefEntryI;
+import jalview.api.SiftsClientI;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.SequenceI;
+import jalview.io.StructureFile;
+import jalview.schemes.ResidueProperties;
+import jalview.structure.StructureMapping;
+import jalview.util.Comparison;
+import jalview.util.DBRefUtils;
+import jalview.util.Format;
+import jalview.util.Platform;
+import jalview.xml.binding.sifts.Entry;
+import jalview.xml.binding.sifts.Entry.Entity;
+import jalview.xml.binding.sifts.Entry.Entity.Segment;
+import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
+import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
+import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
+import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
import mc_view.Atom;
import mc_view.PDBChain;
XMLStreamReader streamReader = XMLInputFactory.newInstance()
.createXMLStreamReader(gzis);
Unmarshaller um = jc.createUnmarshaller();
- return (Entry) um.unmarshal(streamReader);
+ JAXBElement<Entry> jbe = um.unmarshal(streamReader, Entry.class);
+ return jbe.getValue();
} catch (Exception e)
{
e.printStackTrace();
}
String siftFile = pdbId + ".xml.gz";
String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
- String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
- + siftFile;
- File siftsDownloadDir = new File(
- SiftsSettings.getSiftDownloadDirectory());
- if (!siftsDownloadDir.exists())
+
+ /*
+ * Download the file from URL to either
+ * Java: directory of cached downloaded SIFTS files
+ * Javascript: temporary 'file' (in-memory cache)
+ */
+ File downloadTo = null;
+ if (Platform.isJS())
+ {
+ downloadTo = File.createTempFile(siftFile, ".xml.gz");
+ }
+ else
{
- siftsDownloadDir.mkdirs();
+ downloadTo = new File(
+ SiftsSettings.getSiftDownloadDirectory() + siftFile);
+ File siftsDownloadDir = new File(
+ SiftsSettings.getSiftDownloadDirectory());
+ if (!siftsDownloadDir.exists())
+ {
+ siftsDownloadDir.mkdirs();
+ }
}
+
// System.out.println(">> Download ftp url : " + siftsFileFTPURL);
// long now = System.currentTimeMillis();
URL url = new URL(siftsFileFTPURL);
URLConnection conn = url.openConnection();
InputStream inputStream = conn.getInputStream();
FileOutputStream outputStream = new FileOutputStream(
- downloadedSiftsFile);
+ downloadTo);
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = -1;
while ((bytesRead = inputStream.read(buffer)) != -1)
inputStream.close();
// System.out.println(">>> File downloaded : " + downloadedSiftsFile
// + " took " + (System.currentTimeMillis() - now) + "ms");
- return new File(downloadedSiftsFile);
+ return downloadTo;
}
/**