TagXMLWriter { public void write(final HKXFile hkxFile) throws IOException, TransformerException, ParserConfigurationException { TagXMLHandler handler = new TagXMLHandler(); Document document = handler.createDOM(hkxFile.getContentsVersion(), hkxFile.getClassVersion()); Element root = handler.createSection(document, "__data__"); TagXMLDataCreator creator = new TagXMLDataCreator(document); for(HKXObject content : hkxFile.getContentCollection()) { Node contentXML = creator.create(content); root.appendChild(contentXML); } handler.writeToFile(document, outFile); } TagXMLWriter(final File outputFile); void write(final HKXFile hkxFile);  }
@Test public void testWriteDefaultFileToPhysicalFile() throws Exception { File outputFile = File.createTempFile(TEST_BASE_OUTPUT_FILE, ""); TagXMLWriter writer = new TagXMLWriter(outputFile); writer.write(file); assertArrayEquals( Files.toByteArray(outputFile), FileUtils.resourceToByteArray(TEST_BASE_TARGET_RESOURCE)); }