Пример #1
0
  public static void serialize(
      XQueryContext context, SequenceIterator siNode, Properties outputProperties, OutputStream os)
      throws IOException {

    LOG.debug("Serializing started.");
    SAXSerializer sax =
        (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
    try {
      String encoding = outputProperties.getProperty(OutputKeys.ENCODING, "UTF-8");
      Writer writer = new OutputStreamWriter(os, encoding);
      sax.setOutput(writer, outputProperties);
      Serializer serializer = context.getBroker().getSerializer();
      serializer.reset();
      serializer.setProperties(outputProperties);
      serializer.setReceiver(sax);

      sax.startDocument();

      while (siNode.hasNext()) {
        NodeValue next = (NodeValue) siNode.nextItem();
        serializer.toSAX(next);
      }

      sax.endDocument();
      writer.close();

    } catch (Exception e) {
      String txt = "A problem ocurred while serializing the node set";
      LOG.debug(txt + ".", e);
      throw new ExistIOException(txt + ": " + e.getMessage(), e);

    } finally {
      LOG.debug("Serializing done.");
      SerializerPool.getInstance().returnObject(sax);
    }
  }