I have to read an LDIF file, split the entries, modify them and then write the result as LDIF files.
I found an LdifReader at the Apache Directory LDAP API (org.apache.directory.api:api-ldap-client-api
), so I tried that one like this:
Stream<LdifEntry> stream = StreamSupport.stream(reader.spliterator(), false);
Predicate<LdifEntry> isEnabled = entry -> entry.get("pwdAccountLockedTime") == null;
Map<Boolean, List<LdifEntry>> parts = stream.collect(Collectors.partitioningBy(isEnabled));
List<LdifEntry> enabledAccounts = parts.get(true);
List<LdifEntry> disabledAccounts = parts.get(false);
Works well. However, for some reason all the attribute names/ids are lowercased (“pwdAccountLockedTime” becomes “pwdaccountlockedtime”, etc.) but I need them as they are (preserving the case) – in order to keep the same human readability as before.
Any idea how to do that? If needed I will use a different library.
Note: I would like to improve my question, because I got some downvotes. Please tell me, what’s wrong with it or what’s missing.