Update of /var/cvs/src/org/mmbase/util/xml/applicationdata
In directory james.mmbase.org:/tmp/cvs-serv16306

Modified Files:
        NodeReader.java 
Log Message:
replaced NPE with an actual error, improved performance (using  IOUtil), fixed 
a typo


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util/xml/applicationdata


Index: NodeReader.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/util/xml/applicationdata/NodeReader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- NodeReader.java     3 Sep 2008 23:17:25 -0000       1.1
+++ NodeReader.java     22 Apr 2009 15:08:45 -0000      1.2
@@ -27,7 +27,7 @@
  * @application Applications
  * @author Daniel Ockeloen
  * @author Michiel Meeuwissen
- * @version $Id: NodeReader.java,v 1.1 2008/09/03 23:17:25 michiel Exp $
+ * @version $Id: NodeReader.java,v 1.2 2009/04/22 15:08:45 michiel Exp $
  */
 public class NodeReader extends DocumentReader {
     private static final Logger log = 
Logging.getLoggerInstance(NodeReader.class);
@@ -41,6 +41,7 @@
      */
     public NodeReader(InputSource is, ResourceLoader path) {
         super(is, false);
+        if (path == null) throw new NullPointerException();
         this.path = path;
     }
 
@@ -226,25 +227,26 @@
 
     private byte[] readBytesStream(String resourceName) throws IOException {
         InputStream stream = path.getResourceAsStream(resourceName);
+        if (stream == null) {
+            log.error("The resource '" + resourceName + "' could not be 
found");
+            return null;
+        } else {
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        int c = stream.read();
-        while (c != -1) {
-            buffer.write(c);
-            c = stream.read();
-        }
+            IOUtil.copy(stream, buffer);
         return buffer.toByteArray();
     }
+    }
 
-    public void loadBinairyFields(MMObjectNode newNode) {
+    public void loadBinaryFields(MMObjectNode newNode) {
         Set<String> fieldNames = newNode.getBuilder().getFieldNames();
         if(fieldNames!=null && fieldNames.size()>0){
             for (String fieldName : fieldNames) {
                 int fieldDBType = newNode.getBuilder().getDBType(fieldName);
                 if(fieldDBType == Field.TYPE_BINARY){
-                    try{
+                    try {
                         String resource = newNode.getStringValue(fieldName);
                         newNode.setValue(fieldName, readBytesStream(resource));
-                    }catch(Exception setValueEx){
+                    } catch (Exception setValueEx){
                         log.error(setValueEx);
                     }
                 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to