import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
-import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
if (frames[f] instanceof StructureViewerBase)
{
StructureViewerBase viewFrame = (StructureViewerBase) frames[f];
- matchedFile = saveStructureState(ap, jds, pdb, entry, viewIds,
+ matchedFile = saveStructureViewer(ap, jds, pdb, entry, viewIds,
matchedFile, viewFrame);
/*
* Only store each structure viewer's state once in the project
* jar. First time through only (storeDS==false)
*/
String viewId = viewFrame.getViewId();
+ String viewerType = viewFrame.getViewerType().toString();
if (!storeDS && !viewIds.contains(viewId))
{
viewIds.add(viewId);
if (viewerState != null)
{
copyFileToJar(jout, viewerState.getPath(),
- getViewerJarEntryName(viewId));
+ getViewerJarEntryName(viewId), viewerType);
}
else
{
Cache.log.error("Failed to save viewer state for "
+
- viewFrame.getViewerType().toString());
+ viewerType);
}
}
}
if (!pdbfiles.contains(pdbId))
{
pdbfiles.add(pdbId);
- copyFileToJar(jout, matchedFile, pdbId);
+ copyFileToJar(jout, matchedFile, pdbId, pdbId);
}
}
// using save and then load
try
{
- fileName = fileName.replace('\\', '/');
+ fileName = fileName.replace('\\', '/');
System.out.println("Writing jar entry " + fileName);
JarEntry entry = new JarEntry(fileName);
jout.putNextEntry(entry);
String varnaStateFile = varna.getStateInfo(model.rna);
jarEntryName = RNA_PREFIX + viewId + "_" + nextCounter();
- copyFileToJar(jout, varnaStateFile, jarEntryName);
+ copyFileToJar(jout, varnaStateFile, jarEntryName, "Varna");
rnaSessions.put(model, jarEntryName);
}
SecondaryStructure ss = new SecondaryStructure();
* @param jout
* @param infilePath
* @param jarEntryName
+ * @param msg
+ * additional identifying info to log to the console
*/
protected void copyFileToJar(JarOutputStream jout, String infilePath,
- String jarEntryName)
+ String jarEntryName, String msg)
{
try (InputStream is = new FileInputStream(infilePath))
{
File file = new File(infilePath);
if (file.exists() && jout != null)
{
- System.out.println("Writing jar entry " + jarEntryName);
+ System.out.println(
+ "Writing jar entry " + jarEntryName + " (" + msg + ")");
jout.putNextEntry(new JarEntry(jarEntryName));
copyAll(is, jout);
jout.closeEntry();
}
/**
- * Write the data to a new entry of given name in the output jar file
- *
- * @param jout
- * @param jarEntryName
- * @param data
- * @throws IOException
- */
- protected void writeJarEntry(JarOutputStream jout, String jarEntryName,
- byte[] data) throws IOException
- {
- if (jout != null)
- {
- jarEntryName = jarEntryName.replace('\\','/');
- System.out.println("Writing jar entry " + jarEntryName);
- jout.putNextEntry(new JarEntry(jarEntryName));
- DataOutputStream dout = new DataOutputStream(jout);
- dout.write(data, 0, data.length);
- dout.flush();
- jout.closeEntry();
- }
- }
-
- /**
* Copies input to output, in 4K buffers; handles any data (text or binary)
*
* @param in
* @param viewFrame
* @return
*/
- protected String saveStructureState(AlignmentPanel ap, SequenceI jds,
+ protected String saveStructureViewer(AlignmentPanel ap, SequenceI jds,
Pdbids pdb, PDBEntry entry, List<String> viewIds,
String matchedFile, StructureViewerBase viewFrame)
{
String state = svattrib.getStateData(); // Jalview < 2.9
if (state == null || state.isEmpty()) // Jalview >= 2.9
{
- state = readJarEntry(jprovider,
- getViewerJarEntryName(svattrib.getViewId()));
+ String jarEntryName = getViewerJarEntryName(svattrib.getViewId());
+ state = readJarEntry(jprovider, jarEntryName);
}
// TODO or simpler? for each key in oldFiles,
// replace key.getPath() in state with oldFiles.get(key).getFilePath()
{
// add pdb files that should be present in the viewer
StructureData filedat = oldFiles.get(id);
- rewritten.append(filedat.getFilePath()).append(" \"")
- .append(filedat.getFilePath()).append("\"");
+ rewritten.append(" \"").append(filedat.getFilePath()).append("\"");
}
rewritten.append(";");
}