use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class ImportEntriesOperation method execute.
@Override
public void execute() {
// load the file
try {
String json = importFile.read(StandardCharsets.UTF_16);
// de-serialize and add
Journal[] result = generator.fromJson(Journal[].class, json);
for (Journal i : result) {
db().addEntry(i);
indexer().add(i);
}
} catch (IOException e) {
FailToImportEntriesException f = new FailToImportEntriesException("Cannot import from:" + importFile.getFile() + " message:" + e.getMessage());
f.initCause(e);
throw new RuntimeException(f);
}
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class SerializationDBTest method testPersistence.
@Test
public void testPersistence() {
JavaSerializationEntryDatabase database = new JavaSerializationEntryDatabase();
for (int i = 0; i < 10; ++i) {
Journal j = new Journal();
j.setSubject("testPersist");
j.setContent("testPersist");
database.addEntry(j);
}
JavaSerializationEntryDatabase.serialize(new File("testPersist"), database);
database = JavaSerializationEntryDatabase.deSerialize(new File("testPersist"));
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"));
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class CompressMacTransformer method encryptJournal.
@Override
public Journal encryptJournal(Journal j) throws CipherException {
ByteBuffer dateBuffer = ByteBuffer.allocate(8);
dateBuffer.putLong(j.getDate().getTime());
String encrytSubject = encrypt_format(j.getSubject(), new byte[0]);
String encryptContent = encrypt_format(j.getContent(), dateBuffer.array());
Journal result = new Journal();
result.setSubject(encrytSubject);
result.setContent(encryptContent);
result.setDate(j.getDate());
result.setId(j.getId());
return result;
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class CompressMacTransformer method decryptJournal.
@Override
public Journal decryptJournal(Journal j) throws CipherException, CompromisedDataException {
String decSubject = decrypt_format(j.getSubject(), new byte[0]);
String decContent = decrypt_format(j.getContent(), ByteBuffer.allocate(8).putLong(j.getDate().getTime()).array());
Journal result = new Journal();
result.setSubject(decSubject);
result.setContent(decContent);
result.setDate(j.getDate());
result.setId(j.getId());
return result;
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class CompressMacTest method testWrapper.
protected void testWrapper() {
JournalTransformer wrapper;
try {
CommonFunctions.initDir(testDir);
wrapper = createTransformer(new File(testDir.getCanonicalPath() + "/salt"));
} catch (IOException e) {
System.err.println("cannot load salt");
throw new RuntimeException(e);
}
try {
wrapper.setPassword("password");
} catch (FailToSyncCipherDataException e1) {
throw new RuntimeException(e1);
}
Journal j = new Journal();
j.setSubject("test get");
j.setContent("test get content");
try {
Journal result = wrapper.encryptJournal(j);
result = wrapper.decryptJournal(result);
String plainContent = result.getContent();
Assert.assertEquals("test get content", plainContent);
Assert.assertEquals("test get", result.getSubject());
} catch (CipherException | CompromisedDataException e) {
throw new RuntimeException(e);
}
}
Aggregations