import jalview.api.FeatureSettingsModelI;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.ws.dbsources.Pfam;
+import jalview.ws.dbsources.Rfam;
/**
* implements a random access wrapper around a particular datasource, for
protected static final String TAB = "\t";
+ private static final String GZ_EXT = ".gz";
+
/**
* text specifying source of data. usually filename or url.
*/
{
return bytes;
}
+
/**
* a viewport associated with the current file operation. May be null. May
* move to different object.
}
if (!error)
{
- if (fileStr.toLowerCase().endsWith(".gz"))
+ if (fileStr.toLowerCase().endsWith(GZ_EXT))
{
try
{
// GZIPInputStream code borrowed from Aquaria (soon to be open sourced) via
// Kenny Sabir
Exception e = null;
- if (fileStr.toLowerCase().endsWith(".gz"))
+ if (isGzipped(fileStr))
{
try
{
}
/**
+ * Answers true if the filename (or URL) has a format which Jalview recognises
+ * as denoting gzipped content.
+ * <p>
+ * Currently this means having a ".gz" extension, or ending in "/gzipped" or
+ * "?gz=1" (used to retrieve gzipped from Pfam and Rfam respectively).
+ *
+ * @param filename
+ * @return
+ */
+ protected static boolean isGzipped(String filename)
+ {
+ if (filename == null)
+ {
+ return false;
+ }
+ String lower = filename.toLowerCase();
+ return lower.endsWith(GZ_EXT) || lower.endsWith(Pfam.GZIPPED)
+ || lower.endsWith(Rfam.GZIPPED);
+ }
+
+ /**
* sets the suffix string (if any) and returns remainder (if suffix was
* detected)
*
{
// this will be from JavaScript
inFile = file;
- dataIn = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)));
+ dataIn = new BufferedReader(
+ new InputStreamReader(new ByteArrayInputStream(bytes)));
dataName = fileStr;
}
else if (checkFileSource(fileStr))
{
// pass up the reason why we have no source to read from
throw new IOException(MessageManager.formatMessage(
- "exception.failed_to_read_data_from_source",
- new String[]
+ "exception.failed_to_read_data_from_source", new String[]
{ errormessage }));
}
error = false;
*/
abstract public class Pfam extends Xfam
{
+ /*
+ * append to URLs to retrieve as a gzipped file
+ */
+ public static final String GZIPPED = "/gzipped";
+
static final String PFAM_BASEURL_KEY = "PFAM_BASEURL";
private static final String DEFAULT_PFAM_BASEURL = "https://pfam.xfam.org";
@Override
public String getURLSuffix()
{
- return "/alignment/full";
+ return "/alignment/full" + GZIPPED;
}
/*
@Override
public String getURLSuffix()
{
- return "/alignment/seed";
+ return "/alignment/seed" + GZIPPED;
}
/*
private static final String DEFAULT_RFAM_BASEURL = "https://rfam.xfam.org";
+ /*
+ * append to URLs to retrieve as a gzipped file
+ */
+ public static final String GZIPPED = "?gz=1&download=1";
+
@Override
protected String getURLPrefix()
{
@Override
public String getURLSuffix()
{
- return "/alignment/full";
+ return "/alignment/full" + GZIPPED;
}
/*
@Override
public String getURLSuffix()
{
- // to download gzipped file add '?gzip=1'
- return "/alignment/stockholm";
+ return "/alignment/stockholm" + GZIPPED;
}
/*
*/
public abstract class Xfam extends DbSourceProxyImpl
{
-
public Xfam()
{
super();
--- /dev/null
+package jalview.io;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.Test;
+
+public class FileParseTest
+{
+ @Test(groups = "Functional")
+ public void setIsGzipped()
+ {
+ assertFalse(FileParse.isGzipped(null));
+ assertFalse(FileParse.isGzipped("foobar"));
+ assertFalse(FileParse.isGzipped(".gz.foobar"));
+
+ assertTrue(FileParse.isGzipped("abc.gz"));
+ assertTrue(FileParse.isGzipped("abc.GZ"));
+ assertTrue(FileParse.isGzipped(".gz"));
+ assertFalse(FileParse.isGzipped("abc/gz"));
+ assertFalse(FileParse.isGzipped("gz"));
+
+ assertTrue(FileParse.isGzipped("http:/xy.com/abc/gzipped"));
+ assertTrue(FileParse.isGzipped("abc/gzipped"));
+ assertTrue(FileParse.isGzipped("abc/GZIPPED"));
+ assertTrue(FileParse.isGzipped("/gzipped"));
+ assertFalse(FileParse.isGzipped("gzipped"));
+
+ assertTrue(FileParse.isGzipped("http:/xy.com/abc?gz=1"));
+ assertTrue(FileParse.isGzipped("http:/xy.com/abc?GZ=1"));
+ // currently only recognised if the last token on the URL
+ assertFalse(FileParse.isGzipped("http:/xy.com/abc?gz=1&content-type=text/xml"));
+ }
+}