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

Modified Files:
        ResourceLoader.java 
Log Message:
made autodetection of encoding also available for inputstreams


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


Index: ResourceLoader.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/util/ResourceLoader.java,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- ResourceLoader.java 3 Oct 2008 11:09:29 -0000       1.72
+++ ResourceLoader.java 15 Oct 2008 13:58:34 -0000      1.73
@@ -97,7 +97,7 @@
  * <p>For property-files, the java-unicode-escaping is undone on loading, and 
applied on saving, so there is no need to think of that.</p>
  * @author Michiel Meeuwissen
  * @since  MMBase-1.8
- * @version $Id: ResourceLoader.java,v 1.72 2008/10/03 11:09:29 michiel Exp $
+ * @version $Id: ResourceLoader.java,v 1.73 2008/10/15 13:58:34 michiel Exp $
  */
 public class ResourceLoader extends ClassLoader {
 
@@ -841,18 +841,13 @@
     }
 
     /**
-     * Returns a reader for a given resource. This performs the tricky task of 
finding the encoding.
-     * Resources are actually InputStreams (byte arrays), but often they are 
quite text-oriented
-     * (like e.g. XML's or property-files), so this method may be useful.
-     * A resource is supposed to be a property-file if it's name ends in 
".properties", it is
-     * supposed to be XML if it's content starts with &lt;?xml.
-     * @see #getResourceAsStream(String)
+     * A version of [EMAIL PROTECTED] #getReader(String)} which accepts the 
result of [EMAIL PROTECTED] #getResourceAsStream}.
+     * @since MMBase-1.9
      */
-    public Reader getReader(String name) throws IOException {
+    public  Reader getReader(InputStream is, String name) throws IOException {
         try {
-            InputStream is = getResourceAsStream(name);
             if (is == null) return null;
-            if (name.endsWith(".properties")) {
+            if (name != null && name.endsWith(".properties")) {
                 // todo \ u escapes must be escaped to decent Character's.
                 return new TransformingReader(new InputStreamReader(is, 
"UTF-8"), new InverseCharTransformer(new UnicodeEscaper()));
             }
@@ -886,6 +881,18 @@
     }
 
     /**
+     * Returns a reader for a given resource. This performs the tricky task of 
finding the encoding.
+     * Resources are actually InputStreams (byte arrays), but often they are 
quite text-oriented
+     * (like e.g. XML's or property-files), so this method may be useful.
+     * A resource is supposed to be a property-file if it's name ends in 
".properties", it is
+     * supposed to be XML if it's content starts with &lt;?xml.
+     * @see #getResourceAsStream(String)
+     */
+    public Reader getReader(String name) throws IOException {
+        return getReader(getResourceAsStream(name), name);
+    }
+
+    /**
      * Returns a writer for a given resource, so that you can overwrite or 
create it. This performs
      * the tricky task of serializing to the right encoding. It supports the 
same tricks as [EMAIL PROTECTED]
      * #getReader}, but then inversed.
_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to