@Test public void testCreateLabels() throws LabelsBuilderException{ ByteArrayInputStream inputStream = new ByteArrayInputStream(LABELS_XML.getBytes()); LabelsMetaData metaData = LabelsBuilder.createLabels(inputStream); Assert.assertNotNull(metaData); Assert.assertTrue(metaData.isHierarchy()); Assert.assertEquals(NUM_LABELS ,metaData.getNumLabels()); LabelNode hierarchyNode = metaData.getLabelNode(HIERARCHY_NODE_NAME); Set<LabelNode> children = hierarchyNode.getChildren(); Assert.assertEquals(NUM_HIERARCHY_NODE_CHILDREN, children.size()); }
public static LabelsMetaData createLabels(String xmlLabelsFilePath) throws LabelsBuilderException { if (xmlLabelsFilePath == null) { throw new ArgumentNullException("xmlLabelsFilePath"); } File xmlDefFile = new File(xmlLabelsFilePath); if (!xmlDefFile.exists()) { throw new IllegalArgumentException(String.format( "The specified XML file source '%s' does not exist.", xmlDefFile.getAbsolutePath())); } LabelsMetaData result; BufferedInputStream xmlFileInputStream = null; try { xmlFileInputStream = new BufferedInputStream(new FileInputStream(xmlDefFile)); result = createLabels(xmlFileInputStream); } catch (FileNotFoundException e) { throw new LabelsBuilderException( String.format("Error when creating input stream for the file under path: '%s'.", xmlLabelsFilePath)); } finally { if (xmlFileInputStream != null) { try { xmlFileInputStream.close(); } catch (IOException e) { } } } return result; }
LabelsBuilder { public static LabelsMetaData createLabels(String xmlLabelsFilePath) throws LabelsBuilderException { if (xmlLabelsFilePath == null) { throw new ArgumentNullException("xmlLabelsFilePath"); } File xmlDefFile = new File(xmlLabelsFilePath); if (!xmlDefFile.exists()) { throw new IllegalArgumentException(String.format( "The specified XML file source '%s' does not exist.", xmlDefFile.getAbsolutePath())); } LabelsMetaData result; BufferedInputStream xmlFileInputStream = null; try { xmlFileInputStream = new BufferedInputStream(new FileInputStream(xmlDefFile)); result = createLabels(xmlFileInputStream); } catch (FileNotFoundException e) { throw new LabelsBuilderException( String.format("Error when creating input stream for the file under path: '%s'.", xmlLabelsFilePath)); } finally { if (xmlFileInputStream != null) { try { xmlFileInputStream.close(); } catch (IOException e) { } } } return result; } }
LabelsBuilder { public static LabelsMetaData createLabels(String xmlLabelsFilePath) throws LabelsBuilderException { if (xmlLabelsFilePath == null) { throw new ArgumentNullException("xmlLabelsFilePath"); } File xmlDefFile = new File(xmlLabelsFilePath); if (!xmlDefFile.exists()) { throw new IllegalArgumentException(String.format( "The specified XML file source '%s' does not exist.", xmlDefFile.getAbsolutePath())); } LabelsMetaData result; BufferedInputStream xmlFileInputStream = null; try { xmlFileInputStream = new BufferedInputStream(new FileInputStream(xmlDefFile)); result = createLabels(xmlFileInputStream); } catch (FileNotFoundException e) { throw new LabelsBuilderException( String.format("Error when creating input stream for the file under path: '%s'.", xmlLabelsFilePath)); } finally { if (xmlFileInputStream != null) { try { xmlFileInputStream.close(); } catch (IOException e) { } } } return result; }  }
LabelsBuilder { public static LabelsMetaData createLabels(String xmlLabelsFilePath) throws LabelsBuilderException { if (xmlLabelsFilePath == null) { throw new ArgumentNullException("xmlLabelsFilePath"); } File xmlDefFile = new File(xmlLabelsFilePath); if (!xmlDefFile.exists()) { throw new IllegalArgumentException(String.format( "The specified XML file source '%s' does not exist.", xmlDefFile.getAbsolutePath())); } LabelsMetaData result; BufferedInputStream xmlFileInputStream = null; try { xmlFileInputStream = new BufferedInputStream(new FileInputStream(xmlDefFile)); result = createLabels(xmlFileInputStream); } catch (FileNotFoundException e) { throw new LabelsBuilderException( String.format("Error when creating input stream for the file under path: '%s'.", xmlLabelsFilePath)); } finally { if (xmlFileInputStream != null) { try { xmlFileInputStream.close(); } catch (IOException e) { } } } return result; }  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 LabelsMetaData createLabels(String xmlLabelsFilePath) throws LabelsBuilderException { if (xmlLabelsFilePath == null) { throw new ArgumentNullException("xmlLabelsFilePath"); } File xmlDefFile = new File(xmlLabelsFilePath); if (!xmlDefFile.exists()) { throw new IllegalArgumentException(String.format( "The specified XML file source '%s' does not exist.", xmlDefFile.getAbsolutePath())); } LabelsMetaData result; BufferedInputStream xmlFileInputStream = null; try { xmlFileInputStream = new BufferedInputStream(new FileInputStream(xmlDefFile)); result = createLabels(xmlFileInputStream); } catch (FileNotFoundException e) { throw new LabelsBuilderException( String.format("Error when creating input stream for the file under path: '%s'.", xmlLabelsFilePath)); } finally { if (xmlFileInputStream != null) { try { xmlFileInputStream.close(); } catch (IOException e) { } } } return result; }  static LabelsMetaData createLabels(String xmlLabelsFilePath); static LabelsMetaData createLabels(InputStream inputStream); static void dumpLabels(LabelsMetaData labelsMetaData, String xmlDumpFilePath); static void dumpLabels(LabelsMetaData labelsMetaData, OutputStream outputStream);  }