Example 6-9: Returning the input stream for an xmldoc: URL from a CLOB

import java.net.*;
import java.io.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import XMLDocuments;
import Examples;

public class XMLDocURLConnection extends URLConnection {
  Connection conn = null;
  public XMLDocURLConnection (URL u) {
    super(u);
  }
  public void connect() {
    // Don't need to do anything here, but must implement this method
  }
  public InputStream getInputStream() throws IOException {
    Connection conn = null;
    try {
      // Get the default Oracle8i connection for the current user
      conn = Examples.getConnection();
    }
    catch (SQLException s) {
      throw new IOException("Fatal error getting database connection");
    }
    // Return InputStream for the requested "file" in xml_documents table
    return XMLDocuments.getInputStream(conn,url.getFile());
  }
  public void finalize() {
    // Close the database connection when object is garbage-collected
    try { if (conn != null) conn.close(); } catch (SQLException s) {}
  }
}