StreamingOMSerializer serializer = new StreamingOMSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StreamSource(file.getUrl().toString()));
String encoding = reader.getEncoding();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out, encoding);
writer.writeStartDocument(encoding, reader.getVersion());
serializer.serialize(reader, writer, false);
writer.writeEndDocument();
writer.flush();
XMLAssertEx.assertXMLIdentical(file.getUrl(), new ByteArrayInputStream(out.toByteArray()), false);
}