use of com.unboundid.util.PasswordFileReader in project ldapsdk by pingidentity.
the class LDIFDiffTestCase method readChangeRecords.
/**
* Reads the LDIF change records from the specified file.
*
* @param ldifFile The file from which to read the change records. It may
* optionally be compressed, and it may be encrypted if a
* password file is provided.
* @param encPWFile A file containing the encryption passphrase needed to
* read the file. It may be {@code null} if the file is
* not encrypted.
*
* @return The list of LDIF change records that were read.
*
* @throws Exception If an unexpected problem occurs.
*/
private static List<LDIFChangeRecord> readChangeRecords(final File ldifFile, final File encPWFile) throws Exception {
InputStream inputStream = new FileInputStream(ldifFile);
if (encPWFile != null) {
final char[] pwChars = new PasswordFileReader().readPassword(encPWFile);
inputStream = ToolUtils.getPossiblyPassphraseEncryptedInputStream(inputStream, Collections.singleton(pwChars), false, "Enter the passphrase:", "confirm the passphrase:", System.out, System.err).getFirst();
}
inputStream = ToolUtils.getPossiblyGZIPCompressedInputStream(inputStream);
try (LDIFReader ldifReader = new LDIFReader(inputStream)) {
final List<LDIFChangeRecord> changeRecords = new ArrayList<>(10);
while (true) {
final LDIFChangeRecord changeRecord = ldifReader.readChangeRecord();
if (changeRecord == null) {
return changeRecords;
}
changeRecords.add(changeRecord);
}
}
}
Aggregations