@Test public void testCanReadMultipleKeysFrom1File() throws Exception { KeyFilesOperationsPgpImpl fixture = buildFixture(); List<Key> keys = fixture.readKeysFromFile(new File(TestTools.getFileNameForResource("keys/2keysIn1.asc"))); assertEquals(2, keys.size()); }
@Override public List<Key> readKeysFromFile(File file) { try (FileInputStream fis = new FileInputStream(file)) { List<Key> ret = new ArrayList<>(); if (file.getName().endsWith(".asc")) { ArmoredInputSubStream subStream = new ArmoredInputSubStream(fis); while (subStream.hasNextSubStream()) { ret.add(readFromStream(subStream)); } Preconditions.checkArgument(ret.size() > 0, "No keys found"); ret = combinePrivateAndPublicIfAny(ret); } else { ret.add(readFromStream(fis)); } return ret; } catch (Throwable t) { throw new RuntimeException("Can't read key file", t); } }
KeyFilesOperationsPgpImpl implements KeyFilesOperations { @Override public List<Key> readKeysFromFile(File file) { try (FileInputStream fis = new FileInputStream(file)) { List<Key> ret = new ArrayList<>(); if (file.getName().endsWith(".asc")) { ArmoredInputSubStream subStream = new ArmoredInputSubStream(fis); while (subStream.hasNextSubStream()) { ret.add(readFromStream(subStream)); } Preconditions.checkArgument(ret.size() > 0, "No keys found"); ret = combinePrivateAndPublicIfAny(ret); } else { ret.add(readFromStream(fis)); } return ret; } catch (Throwable t) { throw new RuntimeException("Can't read key file", t); } } }
KeyFilesOperationsPgpImpl implements KeyFilesOperations { @Override public List<Key> readKeysFromFile(File file) { try (FileInputStream fis = new FileInputStream(file)) { List<Key> ret = new ArrayList<>(); if (file.getName().endsWith(".asc")) { ArmoredInputSubStream subStream = new ArmoredInputSubStream(fis); while (subStream.hasNextSubStream()) { ret.add(readFromStream(subStream)); } Preconditions.checkArgument(ret.size() > 0, "No keys found"); ret = combinePrivateAndPublicIfAny(ret); } else { ret.add(readFromStream(fis)); } return ret; } catch (Throwable t) { throw new RuntimeException("Can't read key file", t); } }  }
KeyFilesOperationsPgpImpl implements KeyFilesOperations { @Override public List<Key> readKeysFromFile(File file) { try (FileInputStream fis = new FileInputStream(file)) { List<Key> ret = new ArrayList<>(); if (file.getName().endsWith(".asc")) { ArmoredInputSubStream subStream = new ArmoredInputSubStream(fis); while (subStream.hasNextSubStream()) { ret.add(readFromStream(subStream)); } Preconditions.checkArgument(ret.size() > 0, "No keys found"); ret = combinePrivateAndPublicIfAny(ret); } else { ret.add(readFromStream(fis)); } return ret; } catch (Throwable t) { throw new RuntimeException("Can't read key file", t); } }  @Override List<Key> readKeysFromFile(File file); @Override List<Key> readKeysFromText(String text); @Override void exportPublicKey(Key key, String targetFilePathname); @Override String getPublicKeyArmoredRepresentation(Key key); @Override void exportPrivateKey(Key key, String targetFilePathname); @Override void validateDecryptionKeyPassword(String requestedKeyId, Key key, String password); @Override Key readKeyFromFile(String fileName); }
KeyFilesOperationsPgpImpl implements KeyFilesOperations { @Override public List<Key> readKeysFromFile(File file) { try (FileInputStream fis = new FileInputStream(file)) { List<Key> ret = new ArrayList<>(); if (file.getName().endsWith(".asc")) { ArmoredInputSubStream subStream = new ArmoredInputSubStream(fis); while (subStream.hasNextSubStream()) { ret.add(readFromStream(subStream)); } Preconditions.checkArgument(ret.size() > 0, "No keys found"); ret = combinePrivateAndPublicIfAny(ret); } else { ret.add(readFromStream(fis)); } return ret; } catch (Throwable t) { throw new RuntimeException("Can't read key file", t); } }  @Override List<Key> readKeysFromFile(File file); @Override List<Key> readKeysFromText(String text); @Override void exportPublicKey(Key key, String targetFilePathname); @Override String getPublicKeyArmoredRepresentation(Key key); @Override void exportPrivateKey(Key key, String targetFilePathname); @Override void validateDecryptionKeyPassword(String requestedKeyId, Key key, String password); @Override Key readKeyFromFile(String fileName);  }