From a8a58328ebc4af06c25160b037227d2ada26fdb3 Mon Sep 17 00:00:00 2001 From: mrglavas Date: Tue, 21 Jun 2005 19:19:22 +0000 Subject: [PATCH] Synching up XMLReaderFactory with the FactoryFinders. When reading the service provider name from a jar a BufferedReader is used to read the first line from the file. BufferedReader's default buffer size is 8K chars. Since we're only reading one line (the name of a class) this is pretty excessive. Reducing this size significantly to 80 chars. The reader used to read the service provider is never closed if an IOException is thrown while reading from it. Adding a finally block so that the reader will always be closed. git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226251 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/xml/sax/helpers/XMLReaderFactory.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/java/external/src/org/xml/sax/helpers/XMLReaderFactory.java b/java/external/src/org/xml/sax/helpers/XMLReaderFactory.java index b3b75de..f297611 100644 --- a/java/external/src/org/xml/sax/helpers/XMLReaderFactory.java +++ b/java/external/src/org/xml/sax/helpers/XMLReaderFactory.java @@ -7,6 +7,7 @@ package org.xml.sax.helpers; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import org.xml.sax.XMLReader; @@ -59,6 +60,11 @@ final public class XMLReaderFactory private static final String property = "org.xml.sax.driver"; + /** + * Default columns per line. + */ + private static final int DEFAULT_LINE_LENGTH = 80; + /** * Attempt to create an XMLReader from system defaults. * In environments which can support it, the name of the XMLReader @@ -155,19 +161,27 @@ final public class XMLReaderFactory // jkesselm] BufferedReader rd; try { - rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); + rd = new BufferedReader(new InputStreamReader(is, "UTF-8"), DEFAULT_LINE_LENGTH); } catch (java.io.UnsupportedEncodingException e) { - rd = new BufferedReader(new InputStreamReader(is)); + rd = new BufferedReader(new InputStreamReader(is), DEFAULT_LINE_LENGTH); } try { // XXX Does not handle all possible input as specified by the // Jar Service Provider specification className = rd.readLine(); - rd.close(); - } catch (Exception x) { + } + catch (Exception x) { // No provider found } + finally { + try { + // try to close the reader. + rd.close(); + } + // Ignore the exception. + catch (IOException exc) {} + } } }