Search in sources :

Example 6 with PasswordFileReader

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);
        }
    }
}
Also used : PasswordFileReader(com.unboundid.util.PasswordFileReader) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream)

Aggregations

PasswordFileReader (com.unboundid.util.PasswordFileReader)6 File (java.io.File)4 PassphraseEncryptedOutputStream (com.unboundid.util.PassphraseEncryptedOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 PrintWriter (java.io.PrintWriter)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Entry (com.unboundid.ldap.sdk.Entry)1 TopologyRegistryTrustManager (com.unboundid.ldap.sdk.unboundidds.TopologyRegistryTrustManager)1 JSONString (com.unboundid.util.json.JSONString)1 TrustStoreTrustManager (com.unboundid.util.ssl.TrustStoreTrustManager)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1