package org.argeo.naming;
-import static org.argeo.osgi.useradmin.LdifName.dn;
-
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;
/** Basic LDIF writer */
public class LdifWriter {
+ private final static Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
private final Writer writer;
/** Writer must be closed by caller */
/** Stream must be closed by caller */
public LdifWriter(OutputStream out) {
- this(new OutputStreamWriter(out));
+ this(new OutputStreamWriter(out, DEFAULT_CHARSET));
}
public void writeEntry(LdapName name, Attributes attributes) throws IOException {
throw new UserDirectoryException(
"Attribute " + nameAttr.getID() + "=" + nameAttr.get() + " not consistent with DN " + name);
- writer.append(dn.name() + ":").append(name.toString()).append('\n');
+ writer.append(LdapAttrs.DN + ":").append(name.toString()).append('\n');
Attribute objectClassAttr = attributes.get("objectClass");
if (objectClassAttr != null)
writeAttribute(objectClassAttr);
for (NamingEnumeration<? extends Attribute> attrs = attributes.getAll(); attrs.hasMore();) {
Attribute attribute = attrs.next();
- if (attribute.getID().equals(dn.name()) || attribute.getID().equals("objectClass"))
+ if (attribute.getID().equals(LdapAttrs.DN) || attribute.getID().equals("objectClass"))
continue;// skip DN attribute
writeAttribute(attribute);
}