Search in sources :

Example 1 with FailToExportEntriesException

use of net.viperfish.journal.framework.errors.FailToExportEntriesException in project vsDiaryWriter by shilongdai.

the class ExportJournalOperation method execute.

@Override
public void execute() {
    // get all entries
    List<Journal> allJournals = db().getAll();
    Journal[] toExport = allJournals.toArray(new Journal[0]);
    // set the id to null to reassign id when importing
    for (Journal i : toExport) {
        i.setId(null);
    }
    // serialize to JSON and write
    try {
        String result = generator.toJson(toExport);
        outputTarget.write(result, StandardCharsets.UTF_16);
    } catch (IOException e) {
        FailToExportEntriesException f = new FailToExportEntriesException("Cannot export entries to:" + outputTarget + " message:" + e.getMessage());
        f.initCause(e);
        throw new RuntimeException(f);
    }
}
Also used : FailToExportEntriesException(net.viperfish.journal.framework.errors.FailToExportEntriesException) Journal(net.viperfish.journal.framework.Journal) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Journal (net.viperfish.journal.framework.Journal)1 FailToExportEntriesException (net.viperfish.journal.framework.errors.FailToExportEntriesException)1