diff --git a/src/main/java/nl/pvanassen/bplist/converter/ConvertToXml.java b/src/main/java/nl/pvanassen/bplist/converter/ConvertToXml.java index 247714b..134f6f3 100644 --- a/src/main/java/nl/pvanassen/bplist/converter/ConvertToXml.java +++ b/src/main/java/nl/pvanassen/bplist/converter/ConvertToXml.java @@ -213,4 +213,37 @@ private static XMLGregorianCalendar fromDate(Date date) { xmlgc.setTimezone(DatatypeConstants.FIELD_UNDEFINED); return xmlgc; } + + public static void dig(PrintWriter out, XMLElement xml, int indent){ + if(xml == null){ + System.out.println("Something's wrong with the pblist input"); + return; + } + String name = xml.getName(); + // get all attribute + indent(out, indent); + out.print("<" + name); + Iterator attributeNames = xml.enumerateAttributeNames(); + while(attributeNames.hasNext()){ + String attributeName = attributeNames.next(); + out.print(" " + attributeName + "=\"" + xml.getStringAttribute(attributeName) + "\""); + } + out.print(">\n"); + Iterator children = xml.iterateChildren(); + if(!children.hasNext()){ + indent(out, indent); + out.print(xml.getContent() + "\n"); + } + while(children.hasNext()){ + XMLElement child = children.next(); + dig(out, child, indent + 1); + } + indent(out, indent); + out.print("\n"); + } + private static void indent(PrintWriter out, int indent){ + for(int i = 0;i < indent;i++){ + out.print("\t"); + } + } } diff --git a/src/test/java/nl/pvanassen/bplist/BinaryPListParserTest.java b/src/test/java/nl/pvanassen/bplist/BinaryPListParserTest.java index af7db49..d955e4d 100644 --- a/src/test/java/nl/pvanassen/bplist/BinaryPListParserTest.java +++ b/src/test/java/nl/pvanassen/bplist/BinaryPListParserTest.java @@ -1,7 +1,11 @@ package nl.pvanassen.bplist; import java.io.IOException; +import java.io.PrintWriter; +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; import java.util.List; +import java.util.Scanner; import nl.pvanassen.bplist.converter.ConvertToXml; import nl.pvanassen.bplist.ext.nanoxml.XMLElement; @@ -21,6 +25,22 @@ private void test(String baseName) throws IOException { assertEquals(FileHelper.getContent(baseName + ".result"), xmlElement.getChildren().get(0).toString()); } + private void testPrettyPrint(String baseName) throws IOException { + List> elements = elementParser.parseObjectTable(FileHelper.getFile(baseName + ".bplist")); + XMLElement xmlElement = convetToXml.convertToXml(elements); + assertNotNull(xmlElement); + ByteArrayOutputStream outputBufferBOS = new ByteArrayOutputStream(); + PrintWriter outputBufferPW = new PrintWriter(outputBufferBOS); + convetToXml.dig(outputBufferPW, xmlElement, 0); + outputBufferPW.close(); + String output = ""; + Scanner outputBufferScanner = new Scanner(new ByteArrayInputStream(outputBufferBOS.toByteArray())); + while(outputBufferScanner.hasNextLine()){ + output += outputBufferScanner.nextLine() + "\n"; + } + assertEquals(FileHelper.getContent(baseName + ".resultPrettyPrint"), output); + } + @Test public void testAirplay() throws IOException { test("airplay"); @@ -48,5 +68,8 @@ public void testUID() throws IOException { public void testUTF16() throws IOException { test("utf16"); } - + @Test + public void testAirplayPrettyPrint() throws IOException { + testPrettyPrint("airplay"); + } } diff --git a/src/test/resources/airplay.resultPrettyPrint b/src/test/resources/airplay.resultPrettyPrint new file mode 100644 index 0000000..f309a99 --- /dev/null +++ b/src/test/resources/airplay.resultPrettyPrint @@ -0,0 +1,84 @@ + + + + duration + + + 5555.0495 + + + loadedTimeRanges + + + + + duration + + + 5555.0495 + + + start + + + 0.0 + + + + + seekableTimeRanges + + + + + duration + + + 5555.0495 + + + start + + + 0.0 + + + + + playbackBufferFull + + + false + + + readyToPlay + + + true + + + rate + + + 1.0 + + + playbackLikelyToKeepUp + + + true + + + playbackBufferEmpty + + + true + + + position + + + 4.626998904 + + +