Author: niallp
Date: Mon Oct  4 06:15:01 2010
New Revision: 1004123

URL: http://svn.apache.org/viewvc?rev=1004123&view=rev
Log:
IO-162 and IO-178 Minor refactoring to simplify

Modified:
    
commons/proper/io/trunk/src/java/org/apache/commons/io/input/BOMInputStream.java
    
commons/proper/io/trunk/src/java/org/apache/commons/io/input/XmlStreamReader.java

Modified: 
commons/proper/io/trunk/src/java/org/apache/commons/io/input/BOMInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/BOMInputStream.java?rev=1004123&r1=1004122&r2=1004123&view=diff
==============================================================================
--- 
commons/proper/io/trunk/src/java/org/apache/commons/io/input/BOMInputStream.java
 (original)
+++ 
commons/proper/io/trunk/src/java/org/apache/commons/io/input/BOMInputStream.java
 Mon Oct  4 06:15:01 2010
@@ -182,6 +182,18 @@ public class BOMInputStream extends Prox
     }
 
     /**
+     * Return the BOM charset Name - {...@link ByteOrderMark#getCharsetName()}.
+     *
+     * @return The BOM charset Name or null if no BOM found
+     * @throws IOException if an error reading the first bytes of the stream 
occurs
+     * 
+     */
+    public String getBOMCharsetName() throws IOException {
+        getBOM();
+        return (byteOrderMark == null ? null : byteOrderMark.getCharsetName());
+    }
+
+    /**
      * This method reads and either preserves or skips the first bytes in the
      * stream. It behaves like the single-byte <code>read()</code> method,
      * either returning a valid byte or -1 to indicate that the initial bytes

Modified: 
commons/proper/io/trunk/src/java/org/apache/commons/io/input/XmlStreamReader.java
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/XmlStreamReader.java?rev=1004123&r1=1004122&r2=1004123&view=diff
==============================================================================
--- 
commons/proper/io/trunk/src/java/org/apache/commons/io/input/XmlStreamReader.java
 (original)
+++ 
commons/proper/io/trunk/src/java/org/apache/commons/io/input/XmlStreamReader.java
 Mon Oct  4 06:15:01 2010
@@ -447,8 +447,8 @@ public class XmlStreamReader extends Rea
             throws IOException {
         BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, 
BUFFER_SIZE), false, BOMS);
         BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
-        String bomEnc      = (bom.hasBOM() ? bom.getBOM().getCharsetName() : 
null);
-        String xmlGuessEnc = (pis.hasBOM() ? pis.getBOM().getCharsetName() : 
null);
+        String bomEnc      = bom.getBOMCharsetName();
+        String xmlGuessEnc = pis.getBOMCharsetName();
         String xmlEnc = getXmlProlog(pis, xmlGuessEnc);
         this.encoding = calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, pis);
         this.reader = new InputStreamReader(is, encoding);
@@ -469,8 +469,8 @@ public class XmlStreamReader extends Rea
         BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
         String cTMime = getContentTypeMime(httpContentType);
         String cTEnc = getContentTypeEncoding(httpContentType);
-        String bomEnc      = (bom.hasBOM() ? bom.getBOM().getCharsetName() : 
null);
-        String xmlGuessEnc = (pis.hasBOM() ? pis.getBOM().getCharsetName() : 
null);
+        String bomEnc      = bom.getBOMCharsetName();
+        String xmlGuessEnc = pis.getBOMCharsetName();
         String xmlEnc = getXmlProlog(pis, xmlGuessEnc);
         this.encoding = calculateHttpEncoding(cTMime, cTEnc, bomEnc,
                 xmlGuessEnc, xmlEnc, pis, lenient);


Reply via email to