geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bschucha...@apache.org
Subject [07/50] [abbrv] incubator-geode git commit: GEODE-135: Added UnclosableInputStream for SAX parser
Date Fri, 14 Aug 2015 20:39:56 GMT
GEODE-135: Added UnclosableInputStream for SAX parser

This closes #12

In order to block the parser from closing the stream, we wrap the
InputStream in a filter, i.e., UnclosableInputStream, whose close()
function does nothing.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/405daf57
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/405daf57
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/405daf57

Branch: refs/heads/feature/GEODE-77
Commit: 405daf57eea94560e5700c026095b837cf823c93
Parents: 94939c1
Author: lzh <lzhang@ca.ibm.com>
Authored: Tue Jul 28 13:46:48 2015 -0400
Committer: Dan Smith <dsmith@pivotal.io>
Committed: Wed Jul 29 09:46:31 2015 -0700

----------------------------------------------------------------------
 .../internal/cache/xmlcache/CacheXmlParser.java | 26 +++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/405daf57/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/CacheXmlParser.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/CacheXmlParser.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/CacheXmlParser.java
index 9f2cbc0..9b2f5ed 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/CacheXmlParser.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/CacheXmlParser.java
@@ -182,13 +182,37 @@ public class CacheXmlParser extends CacheXml implements ContentHandler
{
    *
    */
   public static CacheXmlParser parse(InputStream is) {
+	  
+    /**
+     * The API doc
+     * http://java.sun.com/javase/6/docs/api/org/xml/sax/InputSource.html for
+     * the SAX InputSource says: "... standard processing of both byte and
+     * character streams is to close them on as part of end-of-parse cleanup, so
+     * applications should not attempt to re-use such streams after they have
+     * been handed to a parser."
+     *
+     * In order to block the parser from closing the stream, we wrap the
+     * InputStream in a filter, i.e., UnclosableInputStream, whose close()
+     * function does nothing.
+     * 
+     */
+    class UnclosableInputStream extends BufferedInputStream {
+      public UnclosableInputStream(InputStream stream) {
+        super(stream);
+      }
+
+      @Override
+      public void close() {
+      }
+    }
+	 
     CacheXmlParser handler = new CacheXmlParser();
     try {
       SAXParserFactory factory = SAXParserFactory.newInstance();
       factory.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, true);
       factory.setValidating(true);
       factory.setNamespaceAware(true);     
-      BufferedInputStream bis = new BufferedInputStream(is);
+      UnclosableInputStream bis = new UnclosableInputStream(is);
       try {
         SAXParser parser = factory.newSAXParser();
         // Parser always reads one buffer plus a little extra worth before


Mime
View raw message