Package nux.xom.io

Examples of nux.xom.io.StreamingSerializer


    BinaryXMLCodec codec = new BinaryXMLCodec();

    if (args.length == 0) { // simply convert from System.in to System.out
      InputStream in = new BufferedInputStream(System.in);
      if (codec.isBnuxDocument(in)) {
        StreamingSerializer ser = factory.createXMLSerializer(System.out, "UTF-8");
        NodeFactory redirector = XOMUtil.getRedirectingNodeFactory(ser);
        codec.deserialize(in, redirector);
      } else { // it's an XML document (or rubbish)
        StreamingSerializer ser = factory.createBinaryXMLSerializer(System.out, compressionLevel);
        NodeFactory redirector = XOMUtil.getRedirectingNodeFactory(ser);
        new Builder(redirector).build(in);
      }
      return;
    }
   
    for (int run=0; run < runs; run++) {
      long s = System.currentTimeMillis();
      for (int i=0; i < args.length; i++) {
        long start, end;
        String fileName = args[i];
        File file = new File(fileName);
        if (file.isDirectory()) continue; // ignore
        System.out.print(fileName + " --> ");
        InputStream in = new FileInputStream(file);       
        OutputStream out = null;
       
        if (fileName.endsWith(".bnux")) {
          NodeFactory redirector = null;
          if (readOnly) {
            redirector = XOMUtil.getNullNodeFactory();
          } else {
            String destFileName = fileName.substring(0, fileName.length() - ".bnux".length());
            System.out.print(destFileName);
            out = new FileOutputStream(destFileName);
            StreamingSerializer ser = factory.createXMLSerializer(out, "UTF-8");
            redirector = XOMUtil.getRedirectingNodeFactory(ser);
          }
         
          start = System.currentTimeMillis();
         
          codec.deserialize(in, redirector); // perform conversion       
        }
        else { // it's a textual XML document
          NodeFactory redirector = null;
          if (readOnly) {
            redirector = XOMUtil.getNullNodeFactory();
          } else {
            String destFileName = fileName + ".bnux";
            System.out.print(destFileName);
            out = new FileOutputStream(destFileName);
            StreamingSerializer ser = codec.createStreamingSerializer(out, compressionLevel);
            redirector = XOMUtil.getRedirectingNodeFactory(ser);
          }

          start = System.currentTimeMillis();
         
View Full Code Here


    return out.toByteArray();
  }
 
  private static byte[] serializeWithStax(Document doc, XMLOutputFactory staxOutputFactory, ByteArrayOutputStream out) throws XMLStreamException, IOException {
    XMLStreamWriter writer = staxOutputFactory.createXMLStreamWriter(out, "UTF-8");
    StreamingSerializer ser = new StreamingSerializerFactory().createStaxSerializer(writer);
    ser.write(doc);
    return out.toByteArray();
  }
View Full Code Here

       
        for (int enc = 0; enc < encodings.length; enc++) {
          try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
           
            StreamingSerializer ser;
//            ser = factory.createXMLSerializer(out, encoding);
//            ((nu.xom.Serializer) ser).setIndent(4);
            ser = factory.createStaxSerializer(outFactory.createXMLStreamWriter(out, encodings[enc]));
            ser.write(expected);
           
//            String s = new String(out.toByteArray());
//            s =  s.substring(0, Math.min(2000, s.length()));
//            System.out.println("\n" + s + "\n");
//            log(out.toByteArray());
View Full Code Here

    return out.toByteArray();
  }
 
  private static byte[] serializeWithStreamingXOM(Document doc, ByteArrayOutputStream out) throws IOException {
    StreamingSerializerFactory factory = new StreamingSerializerFactory();
    StreamingSerializer ser = factory.createXMLSerializer(out, "UTF-8");
//    ser.setIndent(4);
    ser.write(doc);
    return out.toByteArray();
  }
View Full Code Here

    return out.toByteArray();
  }
 
  private static byte[] serializeWithStreamingBnux(Document doc, int compressionLevel, ByteArrayOutputStream out) throws IOException {
    StreamingSerializerFactory factory = new StreamingSerializerFactory();
    StreamingSerializer ser = factory.createBinaryXMLSerializer(out, compressionLevel);
    ser.write(doc);
    return out.toByteArray();
  }
View Full Code Here

    return out.toByteArray();
  }
 
  private static byte[] serializeWithStax(Document doc, XMLOutputFactory staxOutputFactory, ByteArrayOutputStream out) throws XMLStreamException, IOException {
    XMLStreamWriter writer = staxOutputFactory.createXMLStreamWriter(out, "UTF-8");
    StreamingSerializer ser = new StreamingSerializerFactory().createStaxSerializer(writer);
    ser.write(doc);
    return out.toByteArray();
  }
View Full Code Here

TOP

Related Classes of nux.xom.io.StreamingSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.