Search in sources :

Example 1 with TextIOStreamHandler

use of net.viperfish.framework.file.TextIOStreamHandler in project vsDiaryWriter by shilongdai.

the class OperationTest method exportJournals.

private void exportJournals(List<Journal> src) {
    try {
        String exported = new JsonGenerator().toJson(src);
        IOFile exportFile = new IOFile(new File("test.txt"), new TextIOStreamHandler());
        exportFile.write(exported, StandardCharsets.UTF_16);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : JsonGenerator(net.viperfish.framework.serialization.JsonGenerator) TextIOStreamHandler(net.viperfish.framework.file.TextIOStreamHandler) IOException(java.io.IOException) IOFile(net.viperfish.framework.file.IOFile) File(java.io.File) IOFile(net.viperfish.framework.file.IOFile)

Example 2 with TextIOStreamHandler

use of net.viperfish.framework.file.TextIOStreamHandler in project vsDiaryWriter by shilongdai.

the class OperationTest method testExportOperation.

@Test
public void testExportOperation() throws FailToSyncEntryException {
    cleanUp();
    addEntries(20, "toExport");
    List<Journal> all = db.getAll();
    for (Journal i : all) {
        i.setId(null);
    }
    try {
        String expectedOutput = new JsonGenerator().toJson(all.toArray(new Journal[1]));
        new ExportJournalOperation("test.txt").execute();
        IOFile exportFile = new IOFile(new File("test.txt"), new TextIOStreamHandler());
        String actualOutput = exportFile.read(StandardCharsets.UTF_16);
        Assert.assertEquals(expectedOutput, actualOutput);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    cleanUp();
}
Also used : JsonGenerator(net.viperfish.framework.serialization.JsonGenerator) TextIOStreamHandler(net.viperfish.framework.file.TextIOStreamHandler) Journal(net.viperfish.journal.framework.Journal) IOException(java.io.IOException) IOFile(net.viperfish.framework.file.IOFile) File(java.io.File) IOFile(net.viperfish.framework.file.IOFile) Test(org.junit.Test)

Example 3 with TextIOStreamHandler

use of net.viperfish.framework.file.TextIOStreamHandler in project vsDiaryWriter by shilongdai.

the class FileEntryDatabaseTest method testPersistence.

@Test
public void testPersistence() {
    File dir = new File("test");
    FileEntryDatabase database = new FileEntryDatabase(new IOFile(new File(dir, "testPersist"), new TextIOStreamHandler()));
    for (int i = 0; i < 10; ++i) {
        Journal j = new Journal();
        j.setSubject("testPersist");
        j.setContent("testPersist");
        database.addEntry(j);
    }
    database.flush();
    database = new FileEntryDatabase(new IOFile(new File(dir, "testPersist"), new TextIOStreamHandler()));
    database.load();
    int count = 0;
    for (Journal i : database.getAll()) {
        Assert.assertEquals("testPersist", i.getContent());
        Assert.assertEquals("testPersist", i.getSubject());
        count++;
    }
    Assert.assertEquals(10, count);
    CommonFunctions.delete(new File("testPersist"));
}
Also used : TextIOStreamHandler(net.viperfish.framework.file.TextIOStreamHandler) Journal(net.viperfish.journal.framework.Journal) IOFile(net.viperfish.framework.file.IOFile) File(java.io.File) IOFile(net.viperfish.framework.file.IOFile) Test(org.junit.Test) DatabaseTest(net.viperfish.journal.framework.DatabaseTest)

Aggregations

File (java.io.File)3 IOFile (net.viperfish.framework.file.IOFile)3 TextIOStreamHandler (net.viperfish.framework.file.TextIOStreamHandler)3 IOException (java.io.IOException)2 JsonGenerator (net.viperfish.framework.serialization.JsonGenerator)2 Journal (net.viperfish.journal.framework.Journal)2 Test (org.junit.Test)2 DatabaseTest (net.viperfish.journal.framework.DatabaseTest)1