if (errorListener != null) { try { errorListener.error(new TransformerException(e)); } catch (TransformerException e2) { e2.printStackTrace(System.err); } } else e.printStackTrace(System.err);
  void writeStreamResult(Node node, StreamResult sr, int outputMethod,                         String encoding)    throws IOException  {    OutputStream out = null;    boolean created = false;    try      {        out = sr.getOutputStream();        if (out == null)          {            Writer writer = sr.getWriter();            if (writer != null)                out = new WriterOutputStream(writer);              }        if (out == null)          {            String systemId = sr.getSystemId();            try              {                URL url = new URL(systemId);                URLConnection connection = url.openConnection();                // We need to call setDoInput(false), because our                // implementation of the file protocol allows writing                // (unlike Sun), but it will fail with a FileNotFoundException                // if we also open the connection for input and the output                // file doesn't yet exist.                connection.setDoInput(false);                connection.setDoOutput(true);                out = connection.getOutputStream();              }            catch (MalformedURLException e)              {                out = new FileOutputStream(systemId);              }            catch (UnknownServiceException e)              {                URL url = new URL(systemId);                out = new FileOutputStream(url.getPath());              }            created = true;          }        out = new BufferedOutputStream(out);        StreamSerializer serializer =          new StreamSerializer(outputMethod, encoding, null);        if (stylesheet != null)          {            Collection celem = stylesheet.outputCdataSectionElements;            serializer.setCdataSectionElements(celem);          }        serializer.serialize(node, out);        out.flush();      }    finally      {        try          {            if (out != null && created)                out.close();              }        catch (IOException e)          {          }      }  }