X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fio%2FFileParse.java;h=68b5d288ee18a512320f12b1f41a918bf035cbe2;hb=df81a9e1abd4d4424d6d24b37d93f17bffd3649c;hp=7117d0fcf537a5ae211577c0e290a59d8404af84;hpb=6b56f0140b759b789da51aa4ed327d43297a3a5d;p=jalview.git diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 7117d0f..68b5d28 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -39,6 +39,10 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.zip.GZIPInputStream; + +import jalview.ws.dbsources.Pfam; +import jalview.ws.dbsources.Rfam; + /** * implements a random access wrapper around a particular datasource, for * passing to identifyFile and AlignFile objects. @@ -49,6 +53,8 @@ public class FileParse protected static final String TAB = "\t"; + private static final String GZ_EXT = ".gz"; + /** * text specifying source of data. usually filename or url. */ @@ -56,6 +62,7 @@ public class FileParse public File inFile = null; + /** * a viewport associated with the current file operation. May be null. May * move to different object. @@ -182,7 +189,7 @@ public class FileParse } if (!error) { - if (fileStr.toLowerCase().endsWith(".gz")) + if (fileStr.toLowerCase().endsWith(GZ_EXT)) { try { @@ -224,7 +231,7 @@ public class FileParse // 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 { @@ -256,6 +263,27 @@ public class FileParse } /** + * Answers true if the filename (or URL) has a format which Jalview recognises + * as denoting gzipped content. + *

+ * 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) *