KeyFileXmlParser implements KeyFileParser { public KeyFile fromXml(byte[] inputBytes) { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(inputBytes); return parser.fromXml(inputStream, null, KeyFile.class); } catch (KeePassDatabaseUnreadableException e) { return new KeyFile(false); } } KeyFileXmlParser(XmlParser parser); @Override KeyFileBytes readKeyFile(byte[] keyFile); KeyFile fromXml(byte[] inputBytes);  }
@Test public void whenInputIsKeyFileShouldParseFileAndReturnCorrectData() throws IOException { FileInputStream fileInputStream = new FileInputStream(ResourceUtils.getResource("DatabaseWithKeyfile.key")); byte[] keyFileContent = StreamUtils.toByteArray(fileInputStream); SimpleXmlParser parser = new SimpleXmlParser(); KeyFile keyFile = new KeyFileXmlParser(parser).fromXml(keyFileContent); Assert.assertEquals("RP+rYNZL4lrGtDMBPzOuctlh3NAutSG5KGsT38C+qPQ=", keyFile.getKey().getData()); }