);
return;
}
DocumentModifier iterator = new DocumentModifier();
Builder parser = new Builder();
try {
// Separate out the basic I/O by parsing document,
// and then serializing into a byte array.
// This caches the and removes any dependence on the DTD.
Document doc = parser.build(args[0]);
DocType type = doc.getDocType();
if (type != null) {
doc.removeChild(type);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
Serializer serializer = new Serializer(out);
serializer.write(doc);
serializer.flush();
out.close();
byte[] data = out.toByteArray();
warmup(parser, iterator, data, 5);
InputStream raw = new BufferedInputStream(
new ByteArrayInputStream(data)
);
// Try to avoid garbage collection pauses
System.gc(); System.gc(); System.gc();
long prebuild = System.currentTimeMillis();
// Read the entire document into memory
Document document = parser.build(raw);
long postbuild = System.currentTimeMillis();
System.out.println((postbuild - prebuild)
+ "ms to build the document");