// 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();