Package org.forgerock.opendj.ldif
Class LdifChangeRecordWriter
- java.lang.Object
-
- org.forgerock.opendj.ldif.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); }
-
-
Constructor Summary
Constructors Constructor Description LdifChangeRecordWriter(OutputStream out)
Creates 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this change record writer, flushing it first.boolean
containsChanges()
Returnstrue
if changes has already been written in thisLdifChangeRecordWriter
.void
flush()
Flushes this change record writer so that any buffered data is written immediately to underlying stream, flushing the stream if it is alsoFlushable
.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.LdifChangeRecordWriter
setExcludeAllOperationalAttributes(boolean excludeOperationalAttributes)
Specifies whether all operational attributes should be excluded from any change records that are written to LDIF.LdifChangeRecordWriter
setExcludeAllUserAttributes(boolean excludeUserAttributes)
Specifies whether all user attributes should be excluded from any change records that are written to LDIF.LdifChangeRecordWriter
setExcludeAttribute(AttributeDescription attributeDescription)
Excludes the named attribute from any change records that are written to LDIF.LdifChangeRecordWriter
setExcludeBranch(Dn excludeBranch)
Excludes all change records which target entries beneath the named entry (inclusive) from being written to LDIF.LdifChangeRecordWriter
setIncludeAttribute(AttributeDescription attributeDescription)
Ensures that the named attribute is not excluded from any change records that are written to LDIF.LdifChangeRecordWriter
setIncludeBranch(Dn includeBranch)
Ensures that all change records which target entries beneath the named entry (inclusive) are written to LDIF.LdifChangeRecordWriter
setWrapColumn(int wrapColumn)
Specifies the column at which long lines should be wrapped.static String
toString(ChangeRecord change)
Returns the LDIF string representation of the provided change record.LdifChangeRecordWriter
writeChangeRecord(AddRequest change)
Writes anAdd
change record.LdifChangeRecordWriter
writeChangeRecord(DeleteRequest change)
Writes aDelete
change record.LdifChangeRecordWriter
writeChangeRecord(ModifyDnRequest change)
Writes aModifyDN
change record.LdifChangeRecordWriter
writeChangeRecord(ModifyRequest change)
Writes aModify
change record.LdifChangeRecordWriter
writeChangeRecord(ChangeRecord change)
Writes a change record.LdifChangeRecordWriter
writeComment(CharSequence comment)
Writes a comment.
-
-
-
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.
-
close
public void close() throws IOException
Description copied from interface:ChangeRecordWriter
Closes this change record writer, flushing it first. Closing a previously closed change record writer has no effect.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChangeRecordWriter
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an unexpected IO error occurred while closing.
-
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 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:
flush
in interfaceChangeRecordWriter
- Specified by:
flush
in interfaceFlushable
- 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 isfalse
.- Parameters:
addUserFriendlyComments
-true
if user-friendly comments should be added, orfalse
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 isfalse
.- Parameters:
excludeOperationalAttributes
-true
if all operational attributes should be excluded, orfalse
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 isfalse
.- Parameters:
excludeUserAttributes
-true
if all user attributes should be excluded, orfalse
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
.
-
writeChangeRecord
public LdifChangeRecordWriter writeChangeRecord(AddRequest change) throws IOException
Description copied from interface:ChangeRecordWriter
Writes anAdd
change record.- Specified by:
writeChangeRecord
in interfaceChangeRecordWriter
- Parameters:
change
- TheAddRequest
to be written as anAdd
change record.- Returns:
- A reference to this change record writer.
- Throws:
IOException
- If an unexpected IO error occurred while writing the change record.
-
writeChangeRecord
public LdifChangeRecordWriter writeChangeRecord(ChangeRecord change) throws IOException
Description copied from interface:ChangeRecordWriter
Writes a change record.- Specified by:
writeChangeRecord
in interfaceChangeRecordWriter
- Parameters:
change
- TheChangeRecord
to be written.- Returns:
- A reference to this change record writer.
- Throws:
IOException
- If an unexpected IO error occurred while writing the change record.
-
writeChangeRecord
public LdifChangeRecordWriter writeChangeRecord(DeleteRequest change) throws IOException
Description copied from interface:ChangeRecordWriter
Writes aDelete
change record.- Specified by:
writeChangeRecord
in interfaceChangeRecordWriter
- Parameters:
change
- TheDeleteRequest
to be written as anDelete
change record.- Returns:
- A reference to this change record writer.
- Throws:
IOException
- If an unexpected IO error occurred while writing the change record.
-
writeChangeRecord
public LdifChangeRecordWriter writeChangeRecord(ModifyDnRequest change) throws IOException
Description copied from interface:ChangeRecordWriter
Writes aModifyDN
change record.- Specified by:
writeChangeRecord
in interfaceChangeRecordWriter
- Parameters:
change
- TheModifyDNRequest
to be written as anModifyDN
change record.- Returns:
- A reference to this change record writer.
- Throws:
IOException
- If an unexpected IO error occurred while writing the change record.
-
writeChangeRecord
public LdifChangeRecordWriter writeChangeRecord(ModifyRequest change) throws IOException
Description copied from interface:ChangeRecordWriter
Writes aModify
change record.- Specified by:
writeChangeRecord
in interfaceChangeRecordWriter
- Parameters:
change
- TheModifyRequest
to be written as anModify
change record.- Returns:
- A reference to this change record writer.
- Throws:
IOException
- If an unexpected IO error occurred while writing the change record.
-
writeComment
public LdifChangeRecordWriter writeComment(CharSequence comment) throws IOException
Description copied from interface:ChangeRecordWriter
Writes a comment.- Specified by:
writeComment
in interfaceChangeRecordWriter
- Parameters:
comment
- TheCharSequence
to 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
public boolean containsChanges()
Returnstrue
if changes has already been written in thisLdifChangeRecordWriter
.- Returns:
true
if changes has already been written in thisLdifChangeRecordWriter
-
-