Package nux.xom.io

Examples of nux.xom.io.StreamingSerializerFactory


    // some non-standard options for some more in-depth testing:
    int compressionLevel = Integer.getInteger("nux.xom.tests.BinaryXMLConverter.compressionLevel", 0).intValue();
    int runs = Integer.getInteger("nux.xom.tests.BinaryXMLConverter.runs", 1).intValue();
    boolean readOnly = Boolean.getBoolean("nux.xom.tests.BinaryXMLConverter.readOnly");
   
    StreamingSerializerFactory factory = new StreamingSerializerFactory();
    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();
         
View Full Code Here


      method.invoke(fiSerializer, new Object[] {out});
    } catch (Throwable t) {
      throw new Error(t);
    }
   
    new StreamingSerializerFactory().createStaxSerializer(fiSerializer).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

//        "ISCII91",
    };
   
    System.setProperty("nu.xom.Verifier.checkURI", "false");
    XMLOutputFactory outFactory = createXMLOutputFactory(args[0]);
    StreamingSerializerFactory factory = new StreamingSerializerFactory();
   
    int bugs = 0;
    int k = 0;
    for (int i=1; i < args.length; i++) {
      File[] files = IOTestUtil.listXMLFiles(args[i]);
      for (int j=0; j < files.length; j++, k++) {
        File file = files[j];
        if (bogus(file) || ignore(file) || file.isDirectory()) {
          System.out.println("\n" + k + ": IGNORING " + file + " ...");
          continue;
        }
           
        System.out.println("\n" + k + ": now processing " + file + " ...");
        Document expected = getBuilder().build(file);
//        System.out.println(expected.toXML());
        System.out.print("*");
       
        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");
View Full Code Here

    ser.write(doc);
    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

    ser.write(doc);
    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

      method.invoke(fiSerializer, new Object[] {out});
    } catch (Throwable t) {
      throw new Error(t);
    }
   
    new StreamingSerializerFactory().createStaxSerializer(fiSerializer).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.StreamingSerializerFactory

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.