[MOBY-guts] biomoby commit
Eddie Kawas
kawas at dev.open-bio.org
Thu Feb 28 16:27:57 UTC 2008
kawas
Thu Feb 28 11:27:57 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory dev.open-bio.org:/tmp/cvs-serv22127/Java/src/main/org/biomoby/client
Modified Files:
CentralImpl.java
Log Message:
added a new method getResource(URL)
moby-live/Java/src/main/org/biomoby/client CentralImpl.java,1.51,1.52
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java 2007/12/06 18:05:59 1.51
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java 2008/02/28 16:27:57 1.52
@@ -49,6 +49,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.io.InputStream;
+import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
@@ -59,6 +60,7 @@
import java.util.Vector;
import java.util.TreeMap;
import java.util.Comparator;
+import java.util.zip.GZIPInputStream;
/**
* A default implementation of the
@@ -1818,6 +1820,34 @@
throw new MobyException ("No resource found for '" + resourceName + "'.");
}
+ /***************************************************************************
+ * Gets an InputStream on a URL
+ ***************************************************************************/
+ public InputStream getResource(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());
+ }
+ }
/**************************************************************************
* Return a case-insensitive comparator of Strings. It is used to
* create various TreeMaps where keys are strings.
More information about the MOBY-guts
mailing list