[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Dec 6 18:07:16 UTC 2007


gordonp
Thu Dec  6 13:07:16 EST 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util
In directory dev.open-bio.org:/tmp/cvs-serv25949/src/main/ca/ucalgary/seahawk/util

Modified Files:
	HTMLUtils.java 
Log Message:
Added typecheck
moby-live/Java/src/main/ca/ucalgary/seahawk/util HTMLUtils.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/HTMLUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/HTMLUtils.java	2007/07/28 03:45:31	1.4
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/HTMLUtils.java	2007/12/06 18:07:16	1.5
@@ -28,7 +28,7 @@
 		}
 		else if(primary instanceof MobyDataObject){
 		    values = new Vector<MobyDataObject>();
-		    ((Vector) values).add((MobyDataObject) primary);
+		    ((Vector<MobyDataObject>) values).add((MobyDataObject) primary);
 		}
 		else{
 		    // ignore secondaries, they can't be binary
@@ -223,12 +223,49 @@
 	return content;
     }
 
-    public static String getURLContents(URL u) throws Exception{
+    /**
+     * Convenience method to grab all data from a URL into a String.
+     */
+    public static String getURLContents(URL u) throws IOException{
 	StringBuffer buffer = new StringBuffer();
 	LineNumberReader reader = new LineNumberReader(new InputStreamReader(u.openStream()));
 	for(String line = reader.readLine(); line != null; line = reader.readLine()){
-	    buffer.append(line);
+	    buffer.append(line+"\n");
 	}
 	return buffer.toString();
     }
+
+    /**
+     * Convenience method to grab all data from a URL as a byte array (in case it's not text)
+     */
+    public static byte[] getURLContentBytes(URL u) throws IOException{
+	InputStream urlStream = u.openStream();
+
+	byte[] byteBufferChunk = new byte[1024];
+	ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
+	for(int r = urlStream.read(byteBufferChunk, 0, 1024);
+	    r != -1; 
+	    r = urlStream.read(byteBufferChunk, 0, 1024)){
+	    byteBuffer.write(byteBufferChunk, 0, r);
+	}
+	return byteBuffer.toByteArray();
+    }
+
+    /**
+     * Convenience method to grab all data from a input stream into a String.
+     */
+    public static String getInputStreamContents(InputStream resourceStream) throws IOException{
+	StringBuffer xml = new StringBuffer();
+	    
+	// Copy data verbatim 1 k at a time
+	byte[] dataBuffer = new byte[1024];
+	for(int numBytesRead = resourceStream.read(dataBuffer); 
+	    numBytesRead != -1; 
+	    numBytesRead = resourceStream.read(dataBuffer)){
+	    xml.append(new String(dataBuffer, 0, numBytesRead));
+	}
+
+	return xml.toString();
+    }
+
 }




More information about the MOBY-guts mailing list