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;
}

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 ; }
construct a kdb database from the supplied inputstream .
