final JalviewFileChooser chooser = new JalviewFileChooser(
jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(
- MessageManager.getString("label.load_jalview_annotations"));
- chooser.setToolTipText(
- MessageManager.getString("label.load_jalview_annotations"));
+ String tooltip = MessageManager.getString("label.load_jalview_annotations");
+ chooser.setDialogTitle(tooltip);
+ chooser.setToolTipText(tooltip);
chooser.setResponseHandler(0, new Runnable()
{
@Override
*/
package jalview.io;
+import java.awt.Color;
+import java.io.BufferedReader;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
import jalview.analysis.Conservation;
import jalview.api.AlignViewportI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.schemes.ColourSchemeProperty;
import jalview.util.ColorUtils;
-import java.awt.Color;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
public class AnnotationFile
{
- public AnnotationFile()
- {
- init();
- }
+ private static final String GRAPHLINE = "GRAPHLINE";
+
+ private static final String COMBINE = "COMBINE";
- /**
- * character used to write newlines
- */
protected String newline = System.getProperty("line.separator");
+ private StringBuffer text;
+
+ private SequenceI refSeq = null;
+
+ private String refSeqId = null;
+
+ private long nlinesread = 0;
+
+ private String lastread = "";
+
/**
- * set new line string and reset the output buffer
- *
- * @param nl
+ * Constructor
*/
- public void setNewlineString(String nl)
+ public AnnotationFile()
{
- newline = nl;
init();
}
- public String getNewlineString()
- {
- return newline;
- }
-
- StringBuffer text;
-
private void init()
{
text = new StringBuffer("JALVIEW_ANNOTATION" + newline + "# Created: "
}
}
- SequenceI refSeq = null;
-
- String refSeqId = null;
-
public boolean annotateAlignmentView(AlignViewportI viewport, Object file,
DataSourceType protocol)
{
BufferedReader in = null;
try
{
- if (sourceType == DataSourceType.FILE)
- {
- in = FileLoader.getBufferedReader(file);
- }
- else if (sourceType == DataSourceType.URL)
- {
- URL url = new URL(file.toString());
- in = new BufferedReader(new InputStreamReader(url.openStream()));
- }
- else if (sourceType == DataSourceType.PASTE)
- {
- in = new BufferedReader(new StringReader(file.toString()));
- }
- else if (sourceType == DataSourceType.CLASSLOADER)
- {
- java.io.InputStream is = getClass().getResourceAsStream("/" + file);
- if (is != null)
- {
- in = new BufferedReader(new java.io.InputStreamReader(is));
- }
- }
+ in = new FileParse().getBufferedReader(file, sourceType);
if (in != null)
{
return parseAnnotationFrom(al, hidden, in);
}
-
} catch (Exception ex)
{
ex.printStackTrace();
return false;
}
- long nlinesread = 0;
-
- String lastread = "";
-
- private static String GRAPHLINE = "GRAPHLINE", COMBINE = "COMBINE";
-
public boolean parseAnnotationFrom(AlignmentI al, HiddenColumns hidden,
BufferedReader in) throws Exception
{
*/
package jalview.io;
+import java.io.File;
+import java.io.IOException;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import javax.swing.SwingUtilities;
+
import jalview.api.ComplexAlignFile;
import jalview.api.FeatureSettingsModelI;
import jalview.api.FeaturesDisplayedI;
import jalview.schemes.ColourSchemeI;
import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
-import jalview.util.Platform;
import jalview.ws.utils.UrlDownloadClient;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import javax.swing.SwingUtilities;
-
public class FileLoader implements Runnable
{
String file;
return tempStructFile.toString();
}
- /**
- *
- * @param file a File, or a String which is a name of a file
- * @return
- * @throws FileNotFoundException
- */
- public static BufferedReader getBufferedReader(Object file) throws FileNotFoundException {
- if (file instanceof String)
- {
- return new BufferedReader(new FileReader((String) file));
- }
- byte[] bytes = Platform.getFileBytes((File) file);
- if (bytes != null)
- {
- return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)));
- }
- return new BufferedReader(new FileReader((File) file));
- }
-
}
*/
package jalview.io;
-import jalview.api.AlignExportSettingsI;
-import jalview.api.AlignViewportI;
-import jalview.api.AlignmentViewPanel;
-import jalview.api.FeatureSettingsModelI;
-import jalview.util.MessageManager;
-import jalview.util.Platform;
-
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.net.URL;
import java.util.zip.GZIPInputStream;
+import jalview.api.AlignExportSettingsI;
+import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureSettingsModelI;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+
/**
* implements a random access wrapper around a particular datasource, for
* passing to identifyFile and AlignFile objects.
}
private void parse(File file, String fileStr, DataSourceType sourceType,
- boolean isFileObject) throws MalformedURLException, IOException
+ boolean isFileObject) throws IOException
{
bytes = Platform.getFileBytes(file);
dataSourceType = sourceType;
{
// BH 2018 hack for no support for access-origin
bytes = Platform.getFileAsBytes(fileStr);
- dataIn = new BufferedReader(new java.io.InputStreamReader(new ByteArrayInputStream(bytes)));
+ dataIn = new BufferedReader(
+ new InputStreamReader(new ByteArrayInputStream(bytes)));
dataName = fileStr;
}
else if (sourceType == DataSourceType.CLASSLOADER)
{
errormessage = "RESOURCE CANNOT BE LOCATED";
- java.io.InputStream is = getClass()
- .getResourceAsStream("/" + fileStr);
+ InputStream is = getClass().getResourceAsStream("/" + fileStr);
if (is == null)
{
String suffixLess = extractSuffix(fileStr);
}
if (is != null)
{
- dataIn = new BufferedReader(new java.io.InputStreamReader(is));
+ dataIn = new BufferedReader(new InputStreamReader(is));
dataName = fileStr;
}
else
{
return dataSourceType;
}
+
+ /**
+ * Returns a buffered reader for the input object. Returns null, or throws
+ * IOException, on failure.
+ *
+ * @param file
+ * a File, or a String which is a name of a file
+ * @param sourceType
+ * @return
+ * @throws IOException
+ */
+ public BufferedReader getBufferedReader(Object file,
+ DataSourceType sourceType) throws IOException
+ {
+ BufferedReader in = null;
+ byte[] bytes;
+
+ switch (sourceType)
+ {
+ case FILE:
+ if (file instanceof String)
+ {
+ return new BufferedReader(new FileReader((String) file));
+ }
+ bytes = Platform.getFileBytes((File) file);
+ if (bytes != null)
+ {
+ return new BufferedReader(
+ new InputStreamReader(new ByteArrayInputStream(bytes)));
+ }
+ return new BufferedReader(new FileReader((File) file));
+ case URL:
+ URL url = new URL(file.toString());
+ in = new BufferedReader(new InputStreamReader(url.openStream()));
+ break;
+ case RELATIVE_URL: // JalviewJS only
+ bytes = Platform.getFileAsBytes(file.toString());
+ if (bytes != null)
+ {
+ in = new BufferedReader(
+ new InputStreamReader(new ByteArrayInputStream(bytes)));
+ }
+ break;
+ case PASTE:
+ in = new BufferedReader(new StringReader(file.toString()));
+ break;
+ case CLASSLOADER:
+ InputStream is = getClass().getResourceAsStream("/" + file);
+ if (is != null)
+ {
+ in = new BufferedReader(new InputStreamReader(is));
+ }
+ break;
+ }
+
+ return in;
+ }
}