[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Mon Mar 17 14:29:53 UTC 2008


kawas
Mon Mar 17 10:29:53 EDT 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv19159/src/main/org/biomoby/shared

Modified Files:
	Utils.java 
Log Message:
modified getInputStream() such that it can resolve any url and not just HTTP urls.
moby-live/Java/src/main/org/biomoby/shared Utils.java,1.20,1.21
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java	2008/03/03 11:34:17	1.20
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java	2008/03/17 14:29:53	1.21
@@ -19,6 +19,7 @@
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLConnection;
 import java.nio.charset.Charset;
 import java.util.HashSet;
 import java.util.zip.GZIPInputStream;
@@ -529,24 +530,32 @@
 	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());
+	    URLConnection connection = url.openConnection();
+	    // try gzip content encoding iff we have a HTTP url
+	    if (connection instanceof HttpURLConnection) {
+		HttpURLConnection urlConnection = null;
+		urlConnection = (HttpURLConnection) connection;
+		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();
+		}
 	    } else {
-		return urlConnection.getInputStream();
+		return connection.getInputStream();
 	    }
-	    
+
 	} catch (IOException e) {
-	    throw new MobyException ("Error creating input stream: " + e.toString());
+	    throw new MobyException("Error creating input stream: "
+		    + e.toString());
 	}
     }
     




More information about the MOBY-guts mailing list