JaxbSerializableDatabase implements SerializableDatabase { @Override public void save(OutputStream outputStream) throws IOException { final List<String> toEncrypt = new ArrayList<>(); if (keePassFile.getMeta().getMemoryProtection().getProtectTitle()) { toEncrypt.add(org.linguafranca.pwdb.Entry.STANDARD_PROPERTY_NAME_TITLE); } if (keePassFile.getMeta().getMemoryProtection().getProtectURL()) { toEncrypt.add(org.linguafranca.pwdb.Entry.STANDARD_PROPERTY_NAME_URL); } if (keePassFile.getMeta().getMemoryProtection().getProtectUserName()) { toEncrypt.add(org.linguafranca.pwdb.Entry.STANDARD_PROPERTY_NAME_USER_NAME); } if (keePassFile.getMeta().getMemoryProtection().getProtectPassword()) { toEncrypt.add(org.linguafranca.pwdb.Entry.STANDARD_PROPERTY_NAME_PASSWORD); } if (keePassFile.getMeta().getMemoryProtection().getProtectNotes()) { toEncrypt.add(org.linguafranca.pwdb.Entry.STANDARD_PROPERTY_NAME_NOTES); } try { JAXBContext jc = JAXBContext.newInstance(KeePassFile.class); Marshaller u = jc.createMarshaller(); u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); u.setListener(new Marshaller.Listener() { @Override public void beforeMarshal(Object source) { try { if (source instanceof StringField) { StringField field = (StringField) source; if (toEncrypt.contains(field.getKey())) { byte[] encrypted = encryption.encrypt(field.getValue().getValue().getBytes()); String b64 = new String(Base64.encodeBase64(encrypted), "UTF-8"); field.getValue().setValue(b64); field.getValue().setProtected(true); } } } catch (UnsupportedEncodingException e) { throw new IllegalStateException(); } } }); u.marshal(keePassFile, outputStream); } catch (JAXBException e) { throw new IllegalStateException(e); } }  @Override JaxbSerializableDatabase load(InputStream inputStream); @Override void save(OutputStream outputStream); @Override StreamEncryptor getEncryption(); @Override void setEncryption(StreamEncryptor encryption); @Override byte[] getHeaderHash(); @Override void setHeaderHash(byte[] hash); KeePassFile getKeePassFile(); void setKeePassFile(KeePassFile keypassFile);  }
@Test public void createEmptyDatabase() throws Exception { JaxbDatabase db = JaxbDatabase.createEmptyDatabase(); db.save(new KdbxCreds.None(), System.out); }