import java.io.*;
import java.net.*;
+import java.util.zip.GZIPInputStream;
/**
* implements a random access wrapper around a particular datasource, for
{
errormessage = "URL NOT FOUND";
URL url = new URL(fileStr);
- dataIn = new BufferedReader(new InputStreamReader(url.openStream()));
+ //
+ // GZIPInputStream code borrowed from Aquaria (soon to be open sourced) via Kenny Sabir
+ Exception e=null;
+ if (fileStr.endsWith(".gz")) {
+ try {
+ InputStream inputStream = url.openStream();
+ dataIn = new BufferedReader(new InputStreamReader(new GZIPInputStream(inputStream)));
+ dataIn.mark(2048);
+ dataIn.read();
+ dataIn.reset();
+
+ dataName = fileStr;
+ return false;
+ } catch (Exception ex) {
+ e=ex;
+ }
+ }
+
+ try {
+ dataIn = new BufferedReader(new InputStreamReader(url.openStream()));
+ } catch (IOException q) {
+ if (e!=null)
+ {
+ throw new IOException("Failed to resolve GZIP stream", e);
+ }
+ throw q;
+ }
// record URL as name of datasource.
dataName = fileStr;
return false;
--- /dev/null
+/**
+ *
+ */
+package jalview.io;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author jimp
+ *
+ */
+public class FileIOTester
+{
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception
+ {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception
+ {
+ }
+final static File ALIGN_FILE = new File("test/jalview/io/test_gz_fasta.gz");
+
+ @Test
+ public void testGzipIo() throws IOException
+ {
+ String uri;
+ FileParse fp = new FileParse(uri=ALIGN_FILE.getAbsoluteFile().toURI().toString(),AppletFormatAdapter.URL);
+ assertTrue("Couldn't resolve "+uri+" as a valid file",fp.isValid());
+ String type = new IdentifyFile().Identify(fp);
+ assertTrue("Gzipped data from '"+uri+"' identified as '"+type+"'",type.equalsIgnoreCase("FASTA"));
+ }
+
+}