Package org.forgerock.opendj.ldif
Class LDIFChangeRecordWriter
java.lang.Object
org.forgerock.opendj.ldif.LDIFChangeRecordWriter
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,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:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new LDIF change record writer whose destination is the provided output stream.LDIFChangeRecordWriter(Writer writer) Creates a new LDIF change record writer whose destination is the provided character stream writer.LDIFChangeRecordWriter(List<String> ldifLines) Creates a new LDIF change record writer which will append lines of LDIF to the provided list. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this change record writer, flushing it first.booleanReturnstrueif changes has already been written in thisLDIFChangeRecordWriter.voidflush()Flushes this change record writer so that any buffered data is written immediately to underlying stream, flushing the stream if it is alsoFlushable.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.setExcludeAllOperationalAttributes(boolean excludeOperationalAttributes) Specifies whether all operational attributes should be excluded from any change records that are written to LDIF.setExcludeAllUserAttributes(boolean excludeUserAttributes) Specifies whether all user attributes should be excluded from any change records that are written to LDIF.setExcludeAttribute(AttributeDescription attributeDescription) Excludes the named attribute from any change records that are written to LDIF.setExcludeBranch(DN excludeBranch) Excludes all change records which target entries beneath the named entry (inclusive) from being written to LDIF.setIncludeAttribute(AttributeDescription attributeDescription) Ensures that the named attribute is not excluded from any change records that are written to LDIF.setIncludeBranch(DN includeBranch) Ensures that all change records which target entries beneath the named entry (inclusive) are written to LDIF.setWrapColumn(int wrapColumn) Specifies the column at which long lines should be wrapped.static StringtoString(ChangeRecord change) Returns the LDIF string representation of the provided change record.writeChangeRecord(AddRequest change) Writes anAddchange record.writeChangeRecord(DeleteRequest change) Writes aDeletechange record.writeChangeRecord(ModifyDNRequest change) Writes aModifyDNchange record.writeChangeRecord(ModifyRequest change) Writes aModifychange record.writeChangeRecord(ChangeRecord change) Writes a change record.writeComment(CharSequence comment) Writes a comment.
-
Constructor Details
-
LDIFChangeRecordWriter
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
Creates a new LDIF change record writer whose destination is the provided output stream.- Parameters:
out- The output stream to use.
-
LDIFChangeRecordWriter
Creates a new LDIF change record writer whose destination is the provided character stream writer.- Parameters:
writer- The character stream writer to use.
-
-
Method Details
-
toString
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.
-
close
Description copied from interface:ChangeRecordWriterCloses this change record writer, flushing it first. Closing a previously closed change record writer has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChangeRecordWriter- Specified by:
closein interfaceCloseable- Throws:
IOException- If an unexpected IO error occurred while closing.
-
flush
Description copied from interface:ChangeRecordWriterFlushes this change record writer so that any buffered data is written immediately to underlying stream, flushing the stream if it is alsoFlushable.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:
flushin interfaceChangeRecordWriter- Specified by:
flushin interfaceFlushable- Throws:
IOException- If an unexpected IO error occurred while flushing.
-
setAddUserFriendlyComments
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 isfalse.- Parameters:
addUserFriendlyComments-trueif user-friendly comments should be added, orfalseotherwise.- Returns:
- A reference to this
LDIFEntryWriter.
-
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 isfalse.- Parameters:
excludeOperationalAttributes-trueif all operational attributes should be excluded, orfalseotherwise.- Returns:
- A reference to this
LDIFChangeRecordWriter.
-
setExcludeAllUserAttributes
Specifies whether all user attributes should be excluded from any change records that are written to LDIF. The default isfalse.- Parameters:
excludeUserAttributes-trueif all user attributes should be excluded, orfalseotherwise.- Returns:
- A reference to this
LDIFChangeRecordWriter.
-
setExcludeAttribute
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
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
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
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
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
LDIFEntryWriter.
-
writeChangeRecord
Description copied from interface:ChangeRecordWriterWrites anAddchange record.- Specified by:
writeChangeRecordin interfaceChangeRecordWriter- Parameters:
change- TheAddRequestto be written as anAddchange record.- Returns:
- A reference to this change record writer.
- Throws:
IOException- If an unexpected IO error occurred while writing the change record.
-
writeChangeRecord
Description copied from interface:ChangeRecordWriterWrites a change record.- Specified by:
writeChangeRecordin interfaceChangeRecordWriter- Parameters:
change- TheChangeRecordto be written.- Returns:
- A reference to this change record writer.
- Throws:
IOException- If an unexpected IO error occurred while writing the change record.
-
writeChangeRecord
Description copied from interface:ChangeRecordWriterWrites aDeletechange record.- Specified by:
writeChangeRecordin interfaceChangeRecordWriter- Parameters:
change- TheDeleteRequestto be written as anDeletechange record.- Returns:
- A reference to this change record writer.
- Throws:
IOException- If an unexpected IO error occurred while writing the change record.
-
writeChangeRecord
Description copied from interface:ChangeRecordWriterWrites aModifyDNchange record.- Specified by:
writeChangeRecordin interfaceChangeRecordWriter- Parameters:
change- TheModifyDNRequestto be written as anModifyDNchange record.- Returns:
- A reference to this change record writer.
- Throws:
IOException- If an unexpected IO error occurred while writing the change record.
-
writeChangeRecord
Description copied from interface:ChangeRecordWriterWrites aModifychange record.- Specified by:
writeChangeRecordin interfaceChangeRecordWriter- Parameters:
change- TheModifyRequestto be written as anModifychange record.- Returns:
- A reference to this change record writer.
- Throws:
IOException- If an unexpected IO error occurred while writing the change record.
-
writeComment
Description copied from interface:ChangeRecordWriterWrites a comment.- Specified by:
writeCommentin interfaceChangeRecordWriter- Parameters:
comment- TheCharSequenceto be written as a comment.- Returns:
- A reference to this change record writer.
- Throws:
IOException- If an unexpected IO error occurred while writing the comment.
-
containsChanges
Returnstrueif changes has already been written in thisLDIFChangeRecordWriter.- Returns:
trueif changes has already been written in thisLDIFChangeRecordWriter
-