[MOBY-guts] biomoby commit

Martin Senger senger at dev.open-bio.org
Fri Feb 22 09:37:39 UTC 2008


senger
Fri Feb 22 04:37:39 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv29790/src/main/org/biomoby/shared

Modified Files:
	MobyDataType.java Utils.java 
Log Message:
* Change, Fixed: On various places (starting with
org.biomoby.shared.Utils), starting to use Apache commons-io
library (it was necessary in Utils.java because the method
inputStreamToString() was broken anyway).

* Added: a common parent to the command-line clients
(org.biomoby.client.CmdLineHelper) - brinking more and unified
features to these clients.

moby-live/Java/src/main/org/biomoby/shared MobyDataType.java,1.24,1.25 Utils.java,1.17,1.18
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java	2007/12/06 23:40:33	1.24
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java	2008/02/22 09:37:39	1.25
@@ -99,7 +99,6 @@
 	    
 	    MobyDataType[] datatypes;
 	    DataTypeParser p = new DataTypeParser(dataDefURL);
-	    
 	    datatypes = p.getMobyDataTypesFromRDF();
 	    for(MobyDataType dataType: datatypes){
 		dataType.setRegistry(reg);

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java	2006/11/11 23:04:34	1.17
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java	2008/02/22 09:37:39	1.18
@@ -9,6 +9,9 @@
 
 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.BufferedWriter;
@@ -25,6 +28,7 @@
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.nio.CharBuffer;
+import java.nio.charset.Charset;
 
 /**
  * This is a set of several utility methods which may be useful for
@@ -204,13 +208,6 @@
 	return null;
     }
     
-    public static String inputStreamToString(InputStream is, String encoding) throws IOException{
-	InputStreamReader reader = new InputStreamReader(is, encoding);
-	StringBuffer buffer = new StringBuffer();
-	for(char[] chunk = new char[1024]; reader.read(chunk, 0, 1024) != -1; buffer.append(chunk)){}
-	return buffer.toString();
-    }
-
     /*************************************************************************
      * Work in progress. <p>
      *
@@ -233,23 +230,23 @@
 
 	// seems that we are going to read something - so prepare a
 	// default encoding
-	String encoding = new OutputStreamWriter (new ByteArrayOutputStream()).getEncoding();
-	// for 1.5:
-// 	String encoding = Charset.defaultCharset().name();
+ 	String encoding = Charset.defaultCharset().name();
 
 	// path can be absolute...
 	File file = new File (path);
 	if (file.isAbsolute())
-	    return inputStreamToString(new FileInputStream(file), encoding);
+	    return FileUtils.readFileToString (file, encoding);
 
 	// ...or consider it a resource and load it as a resource of
 	// the given class
+	StringWriter result = new StringWriter();
 	InputStream is = null;
 	if (c != null) {
 	    is = c.getClassLoader().getResourceAsStream (path);
-	    if (is != null)
-		return inputStreamToString (is, encoding);
-
+	    if (is != null) {
+		IOUtils.copy (is, result, encoding);
+		return result.toString();
+	    }
 	    // ...or extend the path by the package name of the given
 	    // class
 	    String className = c.getName();
@@ -258,15 +255,19 @@
 		String packageName = className.substring (0, pkgEndIndex);
 		String newPath = packageName.replace ('.', '/') + "/" + path;
 		is = c.getClassLoader().getResourceAsStream (newPath);
-		if (is != null)
-		    return inputStreamToString (is, encoding);
+		if (is != null) {
+		    IOUtils.copy (is, result, encoding);
+		    return result.toString();
+		}
 	    }
 	}
 
 	// ...or (finally) try some general class loader
 	is = Thread.currentThread().getContextClassLoader().getResourceAsStream (path);
-	if (is != null)
-	    return inputStreamToString (is, encoding);
+	if (is != null) {
+	    IOUtils.copy (is, result, encoding);
+	    return result.toString();
+	}
 
 	// sorry, I cannot do more
 	return null;




More information about the MOBY-guts mailing list