[MOBY-guts] biomoby commit
Eddie Kawas
kawas at dev.open-bio.org
Thu Feb 28 16:59:47 UTC 2008
kawas
Thu Feb 28 11:59:47 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv22409/Java/src/main/org/biomoby/shared
Modified Files:
Utils.java
Log Message:
added method getInputStream(URL) that returns an input stream that could be from a gzipped source
moby-live/Java/src/main/org/biomoby/shared Utils.java,1.18,1.19
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java 2008/02/22 09:37:39 1.18
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java 2008/02/28 16:59:47 1.19
@@ -7,28 +7,24 @@
package org.biomoby.shared;
-import org.biomoby.shared.parser.MobyTags;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-
-import java.util.HashSet;
-import java.io.PrintWriter;
+import java.io.BufferedReader;
import java.io.BufferedWriter;
-import java.io.FileWriter;
import java.io.File;
-import java.io.FileInputStream;
+import java.io.FileWriter;
import java.io.IOException;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.ByteArrayOutputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
import java.io.StringWriter;
-import java.net.URL;
+import java.net.HttpURLConnection;
import java.net.MalformedURLException;
-import java.nio.CharBuffer;
+import java.net.URL;
import java.nio.charset.Charset;
+import java.util.HashSet;
+import java.util.zip.GZIPInputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
/**
* This is a set of several utility methods which may be useful for
@@ -525,4 +521,34 @@
javaReserved.add ("volatile");
javaReserved.add ("while");
}
+
+ /***************************************************************************
+ * Gets an InputStream on a URL
+ ***************************************************************************/
+ public static InputStream getInputStream(URL url) throws MobyException {
+ if (url == null)
+ throw new MobyException("Can't get RESOURCE from a null URL!");
+ try {
+ HttpURLConnection urlConnection = null;
+ urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection
+ .setRequestProperty("User-Agent", "jmoby-central/1.0");
+ urlConnection
+ .setRequestProperty("Accept-Encoding", "gzip, deflate");
+ urlConnection.setDefaultUseCaches(false);
+ urlConnection.setUseCaches(false);
+
+ if (("gzip").equalsIgnoreCase(urlConnection.getContentEncoding())) {
+ // handle gzip encoded content
+ return new GZIPInputStream(urlConnection.getInputStream());
+ } else {
+ return urlConnection.getInputStream();
+ }
+
+ } catch (IOException e) {
+ throw new MobyException("Error creating input stream:", e
+ .getCause());
+ }
+ }
+
}
More information about the MOBY-guts
mailing list