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
This commit is contained in:
mrglavas 2005-06-21 19:19:22 +00:00
parent 43b5998999
commit a8a58328eb

View File

@ -7,6 +7,7 @@
package org.xml.sax.helpers; package org.xml.sax.helpers;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
@ -59,6 +60,11 @@ final public class XMLReaderFactory
private static final String property = "org.xml.sax.driver"; 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. * Attempt to create an XMLReader from system defaults.
* In environments which can support it, the name of the XMLReader * In environments which can support it, the name of the XMLReader
@ -155,19 +161,27 @@ final public class XMLReaderFactory
// jkesselm] // jkesselm]
BufferedReader rd; BufferedReader rd;
try { 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) { } catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is)); rd = new BufferedReader(new InputStreamReader(is), DEFAULT_LINE_LENGTH);
} }
try { try {
// XXX Does not handle all possible input as specified by the // XXX Does not handle all possible input as specified by the
// Jar Service Provider specification // Jar Service Provider specification
className = rd.readLine(); className = rd.readLine();
rd.close(); }
} catch (Exception x) { catch (Exception x) {
// No provider found // No provider found
} }
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
} }
} }