KdbSerializer { public static KdbDatabase createKdbDatabase(Credentials credentials, KdbHeader kdbHeader, InputStream inputStream) throws IOException { DataInput dataInput = new LittleEndianDataInputStream(inputStream); checkSignature(dataInput); deserializeHeader(kdbHeader, dataInput); InputStream decryptedInputStream = kdbHeader.createDecryptedInputStream(credentials.getKey(), inputStream); MessageDigest digest = Encryption.getMessageDigestInstance(); DigestInputStream digestInputStream = new DigestInputStream(decryptedInputStream, digest); dataInput = new LittleEndianDataInputStream(digestInputStream); KdbDatabase kdbDatabase = new KdbDatabase(); KdbGroup lastGroup = (KdbGroup) kdbDatabase.getRootGroup(); for (long group = 0; group < kdbHeader.getGroupCount(); group++) { lastGroup = deserializeGroup(lastGroup, dataInput); } for (long entry = 0; entry < kdbHeader.getEntryCount(); entry++) { deserializeEntry(kdbDatabase, dataInput); } if (!Arrays.equals(digest.digest(), kdbHeader.getContentHash())) { throw new IllegalStateException("Hash values did not match"); } digestInputStream.close(); return kdbDatabase; } private  KdbSerializer(); static KdbDatabase createKdbDatabase(Credentials credentials, KdbHeader kdbHeader, InputStream inputStream); static void checkSignature(DataInput dataInput); static Date unpackDate(byte[] buffer);  }
@Test public void testCreateKdbDatabase() throws Exception { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("test123.kdb"); Database database = KdbDatabase.load(new KdbCredentials.Password("123".getBytes()), inputStream); database.visit(new Visitor.Print()); }