Class LdifChangeRecordWriter

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable, ChangeRecordWriter

    public final class LdifChangeRecordWriter
    extends Object
    implements ChangeRecordWriter
    An LDIF change record writer writes change records using the LDAP Data Interchange Format (LDIF) to a user defined destination.

    The following example reads changes from LDIF, and writes the changes to the directory server.

     InputStream ldif = ...;
     LDIFChangeRecordReader reader = new LDIFChangeRecordReader(ldif);
    
     Connection connection = ...;
     connection.bind(...);
    
     ConnectionChangeRecordWriter writer =
             new ConnectionChangeRecordWriter(connection);
     while (reader.hasNext()) {
         ChangeRecord changeRecord = reader.readChangeRecord();
         writer.writeChangeRecord(changeRecord);
     }
     
    See Also:
    RFC 2849 - The LDAP Data Interchange Format (LDIF) - Technical Specification
    • Constructor Detail

      • LdifChangeRecordWriter

        public LdifChangeRecordWriter​(List<String> ldifLines)
        Creates a new LDIF change record writer which will append lines of LDIF to the provided list.
        Parameters:
        ldifLines - The list to which lines of LDIF should be appended.
      • LdifChangeRecordWriter

        public LdifChangeRecordWriter​(OutputStream out)
        Creates a new LDIF change record writer whose destination is the provided output stream.
        Parameters:
        out - The output stream to use.
      • LdifChangeRecordWriter

        public LdifChangeRecordWriter​(Writer writer)
        Creates a new LDIF change record writer whose destination is the provided character stream writer.
        Parameters:
        writer - The character stream writer to use.
    • Method Detail

      • toString

        public static String toString​(ChangeRecord change)
        Returns the LDIF string representation of the provided change record.
        Parameters:
        change - The change record.
        Returns:
        The LDIF string representation of the provided change record.
      • flush

        public void flush()
                   throws IOException
        Description copied from interface: ChangeRecordWriter
        Flushes this change record writer so that any buffered data is written immediately to underlying stream, flushing the stream if it is also Flushable.

        If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

        Specified by:
        flush in interface ChangeRecordWriter
        Specified by:
        flush in interface Flushable
        Throws:
        IOException - If an unexpected IO error occurred while flushing.
      • setAddUserFriendlyComments

        public LdifChangeRecordWriter setAddUserFriendlyComments​(boolean addUserFriendlyComments)
        Specifies whether user-friendly comments should be added whenever distinguished names or UTF-8 attribute values are encountered which contained non-ASCII characters. The default is false.
        Parameters:
        addUserFriendlyComments - true if user-friendly comments should be added, or false otherwise.
        Returns:
        A reference to this LdifChangeRecordWriter.
      • setExcludeAllOperationalAttributes

        public LdifChangeRecordWriter setExcludeAllOperationalAttributes​(boolean excludeOperationalAttributes)
        Specifies whether all operational attributes should be excluded from any change records that are written to LDIF. The default is false.
        Parameters:
        excludeOperationalAttributes - true if all operational attributes should be excluded, or false otherwise.
        Returns:
        A reference to this LdifChangeRecordWriter.
      • setExcludeAllUserAttributes

        public LdifChangeRecordWriter setExcludeAllUserAttributes​(boolean excludeUserAttributes)
        Specifies whether all user attributes should be excluded from any change records that are written to LDIF. The default is false.
        Parameters:
        excludeUserAttributes - true if all user attributes should be excluded, or false otherwise.
        Returns:
        A reference to this LdifChangeRecordWriter.
      • setExcludeAttribute

        public LdifChangeRecordWriter setExcludeAttribute​(AttributeDescription attributeDescription)
        Excludes the named attribute from any change records that are written to LDIF. By default all attributes are included unless explicitly excluded.
        Parameters:
        attributeDescription - The name of the attribute to be excluded.
        Returns:
        A reference to this LdifChangeRecordWriter.
      • setExcludeBranch

        public LdifChangeRecordWriter setExcludeBranch​(Dn excludeBranch)
        Excludes all change records which target entries beneath the named entry (inclusive) from being written to LDIF. By default all change records are written unless explicitly excluded or included.
        Parameters:
        excludeBranch - The distinguished name of the branch to be excluded.
        Returns:
        A reference to this LdifChangeRecordWriter.
      • setIncludeAttribute

        public LdifChangeRecordWriter setIncludeAttribute​(AttributeDescription attributeDescription)
        Ensures that the named attribute is not excluded from any change records that are written to LDIF. By default all attributes are included unless explicitly excluded.
        Parameters:
        attributeDescription - The name of the attribute to be included.
        Returns:
        A reference to this LdifChangeRecordWriter.
      • setIncludeBranch

        public LdifChangeRecordWriter setIncludeBranch​(Dn includeBranch)
        Ensures that all change records which target entries beneath the named entry (inclusive) are written to LDIF. By default all change records are written unless explicitly excluded or included.
        Parameters:
        includeBranch - The distinguished name of the branch to be included.
        Returns:
        A reference to this LdifChangeRecordWriter.
      • setWrapColumn

        public LdifChangeRecordWriter setWrapColumn​(int wrapColumn)
        Specifies the column at which long lines should be wrapped. A value less than or equal to zero (the default) indicates that no wrapping should be performed.
        Parameters:
        wrapColumn - The column at which long lines should be wrapped.
        Returns:
        A reference to this LdifChangeRecordWriter.