[jdom-interest] best way to build JDOM from URLConnection?

John Interrante jinterra at nycap.rr.com
Thu Nov 2 05:25:41 PST 2000

What's the best way (in terms of performance, speed, and correctness)
to build a JDOM document from an URL connection?  Let me illustrate:

    // Open the connection

    URL url = new URL(stringUrl);
    URLConnection connection = url.openConnection();

    connection.setRequestProperty("Content-type", CONTENT_TYPE);
    connection.setRequestProperty("Content-transfer-encoding", CONTENT_ENCODING);

    // Send the HTTP request

    OutputStream output = connection.getOutputStream();
    try {
        Document request = createRequest(test);
        xmlOutputter_.output(request, output);
    finally {

    // Parse the HTTP response and try to build a JDOM document

    Reader reply = new InputStreamReader(connection.getInputStream(), CONTENT_ENCODING);
    Document doc = builder_.build(reply);

    // Or would an InputStream be better than a Reader?

    InputStream reply = connection.getInputStream();
    Document doc = builder_.build(reply);

    // And of course, we should use a buffered reader or inputstream...


This is a case of two applications exchanging XML documents.  The
encoding has been agreed upon and is the same for both the HTTP
connection (CONTENT_ENCODING) and the XML documents which are the body
of the HTTP request/reply.  I'm just wondering whether we should
explicitly instantiate a Reader since we already know the encoding, or
if it's still better to pass an InputStream to the builder and the
underlying XML parser.  We're using both JDOM and Xerces out of CVS,
i.e., Xerces 1.2.1+ and JDOM beta 5+.

John Interrante * Niskayuna, NY * GE CRD, Web and E-Business Solutions

More information about the jdom-interest mailing list