Package org.forgerock.opendj.ldif
Class LdifEntryWriter
- java.lang.Object
-
- org.forgerock.opendj.ldif.LdifEntryWriter
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,EntryWriter
public final class LdifEntryWriter extends Object implements EntryWriter
An LDIF entry writer writes attribute value records (entries) using the LDAP Data Interchange Format (LDIF) to a user defined destination.
-
-
Constructor Summary
Constructors Constructor Description LdifEntryWriter(OutputStream out)Creates a new LDIF entry writer whose destination is the provided output stream.LdifEntryWriter(Writer writer)Creates a new LDIF entry writer whose destination is the provided character stream writer.LdifEntryWriter(List<String> ldifLines)Creates a new LDIF entry 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 voidclose()Closes this entry writer, flushing it first.voidflush()Flushes this entry writer so that any buffered data is written immediately to underlying stream, flushing the stream if it is alsoFlushable.longgetSkippedCount()Returns the number of entries provided towriteEntry(Entry)which have been ignored because they were excluded by the writer's filtering configuration.longgetWrittenCount()Returns the number of entries provided towriteEntry(Entry)which have been written to the LDIF output file.LdifEntryWritersetAddUserFriendlyComments(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.LdifEntryWritersetExcludeAllOperationalAttributes(boolean excludeOperationalAttributes)Specifies whether all operational attributes should be excluded from any entries that are written to LDIF.LdifEntryWritersetExcludeAllUserAttributes(boolean excludeUserAttributes)Specifies whether all user attributes should be excluded from any entries that are written to LDIF.LdifEntryWritersetExcludeAttribute(AttributeDescription attributeDescription)Excludes the named attribute from any entries that are written to LDIF.LdifEntryWritersetExcludeBranch(Dn excludeBranch)Excludes all entries beneath the named entry (inclusive) from being written to LDIF.LdifEntryWritersetIncludeAttribute(AttributeDescription attributeDescription)Ensures that the named attribute is not excluded from any entries that are written to LDIF.LdifEntryWritersetIncludeBranch(Dn includeBranch)Ensures that all entries beneath the named entry (inclusive) are written to LDIF.LdifEntryWritersetIncludeExcludeFilters(Collection<Filter> includeFilters, Collection<Filter> excludeFilters)Sets the filters to include / exclude entries.LdifEntryWritersetWrapColumn(int wrapColumn)Specifies the column at which long lines should be wrapped.static StringtoString(Entry entry)Returns the LDIF string representation of the provided entry.LdifEntryWriterwriteComment(CharSequence comment)Writes a comment.LdifEntryWriterwriteEntry(Entry entry)Writes an entry.
-
-
-
Constructor Detail
-
LdifEntryWriter
public LdifEntryWriter(List<String> ldifLines)
Creates a new LDIF entry writer which will append lines of LDIF to the provided list.- Parameters:
ldifLines- The list to which lines of LDIF should be appended.
-
LdifEntryWriter
public LdifEntryWriter(OutputStream out)
Creates a new LDIF entry writer whose destination is the provided output stream.- Parameters:
out- The output stream to use.
-
LdifEntryWriter
public LdifEntryWriter(Writer writer)
Creates a new LDIF entry writer whose destination is the provided character stream writer.- Parameters:
writer- The character stream writer to use.
-
-
Method Detail
-
toString
public static String toString(Entry entry)
Returns the LDIF string representation of the provided entry.- Parameters:
entry- The entry.- Returns:
- The LDIF string representation of the provided entry.
-
close
public void close() throws IOExceptionDescription copied from interface:EntryWriterCloses this entry writer, flushing it first. Closing a previously closed entry writer has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceEntryWriter- Throws:
IOException- If an unexpected IO error occurred while closing.
-
flush
public void flush() throws IOExceptionDescription copied from interface:EntryWriterFlushes this entry 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 interfaceEntryWriter- Specified by:
flushin interfaceFlushable- Throws:
IOException- If an unexpected IO error occurred while flushing.
-
setAddUserFriendlyComments
public LdifEntryWriter 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-trueif user-friendly comments should be added, orfalseotherwise.- Returns:
- A reference to this
LdifEntryWriter.
-
setExcludeAllOperationalAttributes
public LdifEntryWriter setExcludeAllOperationalAttributes(boolean excludeOperationalAttributes)
Specifies whether all operational attributes should be excluded from any entries that are written to LDIF. The default isfalse.- Parameters:
excludeOperationalAttributes-trueif all operational attributes should be excluded, orfalseotherwise.- Returns:
- A reference to this
LdifEntryWriter.
-
setExcludeAllUserAttributes
public LdifEntryWriter setExcludeAllUserAttributes(boolean excludeUserAttributes)
Specifies whether all user attributes should be excluded from any entries that are written to LDIF. The default isfalse.- Parameters:
excludeUserAttributes-trueif all user attributes should be excluded, orfalseotherwise.- Returns:
- A reference to this
LdifEntryWriter.
-
setExcludeAttribute
public LdifEntryWriter setExcludeAttribute(AttributeDescription attributeDescription)
Excludes the named attribute from any entries 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
LdifEntryWriter.
-
setExcludeBranch
public LdifEntryWriter setExcludeBranch(Dn excludeBranch)
Excludes all entries beneath the named entry (inclusive) from being written to LDIF. By default all entries are written unless explicitly excluded or included by branches or filters.- Parameters:
excludeBranch- The distinguished name of the branch to be excluded.- Returns:
- A reference to this
LdifEntryWriter.
-
setIncludeAttribute
public LdifEntryWriter setIncludeAttribute(AttributeDescription attributeDescription)
Ensures that the named attribute is not excluded from any entries 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
LdifEntryWriter.
-
setIncludeBranch
public LdifEntryWriter setIncludeBranch(Dn includeBranch)
Ensures that all entries beneath the named entry (inclusive) are written to LDIF. By default all entries are written unless explicitly excluded or included by branches or filters.- Parameters:
includeBranch- The distinguished name of the branch to be included.- Returns:
- A reference to this
LdifEntryWriter.
-
setIncludeExcludeFilters
public LdifEntryWriter setIncludeExcludeFilters(Collection<Filter> includeFilters, Collection<Filter> excludeFilters)
Sets the filters to include / exclude entries. By default all entries are read unless explicitly excluded or included by branches or filters.- Parameters:
includeFilters- entries which match any include filter will be included from LDIF.excludeFilters- entries which match any exclude filter will be excluded from LDIF.- Returns:
- A reference to this
LdifEntryReader.
-
setWrapColumn
public LdifEntryWriter 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
LdifEntryWriter.
-
writeComment
public LdifEntryWriter writeComment(CharSequence comment) throws IOException
Description copied from interface:EntryWriterWrites a comment.- Specified by:
writeCommentin interfaceEntryWriter- Parameters:
comment- TheCharSequenceto be written as a comment.- Returns:
- A reference to this entry writer.
- Throws:
IOException- If an unexpected IO error occurred while writing the comment.
-
writeEntry
public LdifEntryWriter writeEntry(Entry entry) throws IOException
Description copied from interface:EntryWriterWrites an entry.- Specified by:
writeEntryin interfaceEntryWriter- Parameters:
entry- TheEntryto be written.- Returns:
- A reference to this entry writer.
- Throws:
IOException- If an unexpected IO error occurred while writing the entry.
-
getSkippedCount
public long getSkippedCount()
Returns the number of entries provided towriteEntry(Entry)which have been ignored because they were excluded by the writer's filtering configuration.- Returns:
- the number of skipped entries
-
getWrittenCount
public long getWrittenCount()
Returns the number of entries provided towriteEntry(Entry)which have been written to the LDIF output file.- Returns:
- the number of entries written to the LDIF output file
-
-