@Test public void testDumpLabels() throws LabelsBuilderException{ ByteArrayInputStream inputStream = new ByteArrayInputStream(LABELS_XML.getBytes()); LabelsMetaData metaData = LabelsBuilder.createLabels(inputStream); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LabelsBuilder.dumpLabels(metaData, outputStream); metaData = LabelsBuilder.createLabels(new ByteArrayInputStream(outputStream.toByteArray())); LabelNode hierarchyNode = metaData.getLabelNode(HIERARCHY_NODE_NAME); Set<LabelNode> children = hierarchyNode.getChildren(); Assert.assertEquals(NUM_HIERARCHY_NODE_CHILDREN, children.size()); }
public static void dumpLabels(LabelsMetaData labelsMetaData, String xmlDumpFilePath) throws LabelsBuilderException { if (xmlDumpFilePath == null) { throw new ArgumentNullException("xmlDumpFilePath"); } File xmlDumpFile = new File(xmlDumpFilePath); boolean fileExists = xmlDumpFile.exists(); BufferedOutputStream fileOutStream = null; try { if (!fileExists) { xmlDumpFile.createNewFile(); } fileOutStream = new BufferedOutputStream(new FileOutputStream(xmlDumpFile)); dumpLabels(labelsMetaData, fileOutStream); } catch (IOException exception) { if (!fileExists) { xmlDumpFile.delete(); } throw new LabelsBuilderException("Error creating file output stream, to which labels meta-data has to be dumped."); } finally { if (fileOutStream != null) { try { fileOutStream.close(); } catch (IOException ex) { } } } }
LabelsBuilder { public static void dumpLabels(LabelsMetaData labelsMetaData, String xmlDumpFilePath) throws LabelsBuilderException { if (xmlDumpFilePath == null) { throw new ArgumentNullException("xmlDumpFilePath"); } File xmlDumpFile = new File(xmlDumpFilePath); boolean fileExists = xmlDumpFile.exists(); BufferedOutputStream fileOutStream = null; try { if (!fileExists) { xmlDumpFile.createNewFile(); } fileOutStream = new BufferedOutputStream(new FileOutputStream(xmlDumpFile)); dumpLabels(labelsMetaData, fileOutStream); } catch (IOException exception) { if (!fileExists) { xmlDumpFile.delete(); } throw new LabelsBuilderException("Error creating file output stream, to which labels meta-data has to be dumped."); } finally { if (fileOutStream != null) { try { fileOutStream.close(); } catch (IOException ex) { } } } } }
LabelsBuilder { public static void dumpLabels(LabelsMetaData labelsMetaData, String xmlDumpFilePath) throws LabelsBuilderException { if (xmlDumpFilePath == null) { throw new ArgumentNullException("xmlDumpFilePath"); } File xmlDumpFile = new File(xmlDumpFilePath); boolean fileExists = xmlDumpFile.exists(); BufferedOutputStream fileOutStream = null; try { if (!fileExists) { xmlDumpFile.createNewFile(); } fileOutStream = new BufferedOutputStream(new FileOutputStream(xmlDumpFile)); dumpLabels(labelsMetaData, fileOutStream); } catch (IOException exception) { if (!fileExists) { xmlDumpFile.delete(); } throw new LabelsBuilderException("Error creating file output stream, to which labels meta-data has to be dumped."); } finally { if (fileOutStream != null) { try { fileOutStream.close(); } catch (IOException ex) { } } } }  }
LabelsBuilder { public static void dumpLabels(LabelsMetaData labelsMetaData, String xmlDumpFilePath) throws LabelsBuilderException { if (xmlDumpFilePath == null) { throw new ArgumentNullException("xmlDumpFilePath"); } File xmlDumpFile = new File(xmlDumpFilePath); boolean fileExists = xmlDumpFile.exists(); BufferedOutputStream fileOutStream = null; try { if (!fileExists) { xmlDumpFile.createNewFile(); } fileOutStream = new BufferedOutputStream(new FileOutputStream(xmlDumpFile)); dumpLabels(labelsMetaData, fileOutStream); } catch (IOException exception) { if (!fileExists) { xmlDumpFile.delete(); } throw new LabelsBuilderException("Error creating file output stream, to which labels meta-data has to be dumped."); } finally { if (fileOutStream != null) { try { fileOutStream.close(); } catch (IOException ex) { } } } }  static LabelsMetaData createLabels(String xmlLabelsFilePath); static LabelsMetaData createLabels(InputStream inputStream); static void dumpLabels(LabelsMetaData labelsMetaData, String xmlDumpFilePath); static void dumpLabels(LabelsMetaData labelsMetaData, OutputStream outputStream); }
LabelsBuilder { public static void dumpLabels(LabelsMetaData labelsMetaData, String xmlDumpFilePath) throws LabelsBuilderException { if (xmlDumpFilePath == null) { throw new ArgumentNullException("xmlDumpFilePath"); } File xmlDumpFile = new File(xmlDumpFilePath); boolean fileExists = xmlDumpFile.exists(); BufferedOutputStream fileOutStream = null; try { if (!fileExists) { xmlDumpFile.createNewFile(); } fileOutStream = new BufferedOutputStream(new FileOutputStream(xmlDumpFile)); dumpLabels(labelsMetaData, fileOutStream); } catch (IOException exception) { if (!fileExists) { xmlDumpFile.delete(); } throw new LabelsBuilderException("Error creating file output stream, to which labels meta-data has to be dumped."); } finally { if (fileOutStream != null) { try { fileOutStream.close(); } catch (IOException ex) { } } } }  static LabelsMetaData createLabels(String xmlLabelsFilePath); static LabelsMetaData createLabels(InputStream inputStream); static void dumpLabels(LabelsMetaData labelsMetaData, String xmlDumpFilePath); static void dumpLabels(LabelsMetaData labelsMetaData, OutputStream outputStream);  }