Search in sources :

Example 1 with JseXmlReader

use of com.xenoage.utils.jse.xml.JseXmlReader in project Zong by Xenoage.

the class FilesystemIndexReaderTest method test.

@Test
public void test() throws Exception {
    // read file
    FilesystemIndex index = FilesystemIndexReader.read(new JseXmlReader(jsePlatformUtils().openFile("data/test/index/FilesystemIndexReaderTest.xml")));
    // check content
    List<? extends FilesystemItem> items;
    assertEquals(0, index.listFiles("/").size());
    assertEquals(2, (items = index.listDirectories("/")).size());
    assertEquals(true, containsItem(items, "dir"));
    assertEquals(true, containsItem(items, "dirempty"));
    assertEquals(2, (items = index.listFiles("/dir/")).size());
    assertEquals(true, containsItem(items, "file1"));
    assertEquals(1000, (long) index.findFile("dir/file1").getSizeInBytes());
    assertEquals(2000, (long) index.findFile("/dir/file2").getSizeInBytes());
    assertEquals(true, containsItem(items, "file2"));
    assertEquals(1, (items = index.listDirectories("/dir/")).size());
    assertEquals(1, (items = index.listDirectories("/dir/subdir")).size());
    assertEquals(0, (items = index.listDirectories("/dir/deadend")).size());
    assertEquals(0, index.listFiles("dirempty").size());
    assertEquals(0, index.listDirectories("dirempty").size());
}
Also used : JseXmlReader(com.xenoage.utils.jse.xml.JseXmlReader) Test(org.junit.Test)

Example 2 with JseXmlReader

use of com.xenoage.utils.jse.xml.JseXmlReader in project Zong by Xenoage.

the class MusicXMLDemoFilesTest method test.

private void test(boolean reload) throws Exception {
    long totalMusicXMLReadingTime = 0;
    long lastTime = 0;
    for (String dir : dirs) {
        for (File file : JseFileUtils.listFiles(new File(dir), plainMusicXMLFilenameFilter, false)) {
            System.out.println(file);
            lastTime = System.currentTimeMillis();
            XmlReader reader = new JseXmlReader(new FileInputStream(file));
            try {
                lastTime = System.currentTimeMillis();
                // load the document
                MusicXMLDocument doc = MusicXMLDocument.read(reader);
                if (reload) {
                    // write the document into memory
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    doc.write(new JseXmlWriter(bos));
                    bos.close();
                    // reload it from memory
                    ByteArrayInputStream in = new ByteArrayInputStream(bos.toByteArray());
                    MusicXMLDocument.read(new JseXmlReader(in));
                    in.close();
                // doc.write(new JseXmlWriter(new JseOutputStream(new File("test.xml"))));
                }
                totalMusicXMLReadingTime += (System.currentTimeMillis() - lastTime);
            } catch (XmlException ex) {
                throw new Exception("Failed for " + dir + "/" + file.getName() + ": " + ex.getMessage(), ex);
            }
        }
    }
    // print time
    System.out.println("Total time for read" + (reload ? "/write/read: " : ": ") + totalMusicXMLReadingTime + " ms");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XmlException(com.xenoage.utils.xml.XmlException) JseXmlWriter(com.xenoage.utils.jse.xml.JseXmlWriter) JseXmlReader(com.xenoage.utils.jse.xml.JseXmlReader) XmlReader(com.xenoage.utils.xml.XmlReader) MusicXMLDocument(com.xenoage.zong.musicxml.MusicXMLDocument) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) XmlException(com.xenoage.utils.xml.XmlException) JseXmlReader(com.xenoage.utils.jse.xml.JseXmlReader)

Aggregations

JseXmlReader (com.xenoage.utils.jse.xml.JseXmlReader)2 JseXmlWriter (com.xenoage.utils.jse.xml.JseXmlWriter)1 XmlException (com.xenoage.utils.xml.XmlException)1 XmlReader (com.xenoage.utils.xml.XmlReader)1 MusicXMLDocument (com.xenoage.zong.musicxml.MusicXMLDocument)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Test (org.junit.Test)1