Package org.opends.server.util
Class LDIFWriter
- java.lang.Object
-
- org.opends.server.util.LDIFWriter
-
- All Implemented Interfaces:
Closeable,AutoCloseable
@PublicAPI(stability=UNCOMMITTED, mayInstantiate=true, mayExtend=false, mayInvoke=true) public final class LDIFWriter extends Object implements Closeable
This class provides a mechanism for writing entries in LDIF form to a file or an output stream.
-
-
Constructor Summary
Constructors Constructor Description LDIFWriter(LDIFExportConfig exportConfig)Creates a new LDIF writer with the provided configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidappendLDIFSeparatorAndValue(StringBuilder buffer, ByteSequence valueBytes)Appends an LDIF separator and properly-encoded form of the given value to the provided buffer.static voidappendLDIFSeparatorAndValue(StringBuilder buffer, ByteSequence valueBytes, boolean isURL, boolean isBase64)Appends an LDIF separator and properly-encoded form of the given value to the provided buffer.voidclose()Closes the LDIF writer and the underlying output stream or file.voidflush()Flushes the data written to the output stream or underlying file.voidwriteAddChangeRecord(Entry entry)Writes an add change record for the provided entry.voidwriteChangeRecord(ChangeRecordEntry changeRecord)Writes a change record entry for the provided change record.voidwriteComment(org.forgerock.i18n.LocalizableMessage comment, int wrapColumn)Writes the provided comment to the LDIF file, optionally wrapping near the specified column.voidwriteDeleteChangeRecord(Entry entry, boolean commentEntry)Writes a delete change record for the provided entry, optionally including a comment with the full entry contents.booleanwriteEntries(Collection<Entry> entries)Iterates over each entry contained in the map and writes out the entry in LDIF format.booleanwriteEntry(Entry entry)Writes the provided entry to LDIF.static voidwriteLDIFLine(StringBuilder line, BufferedWriter writer, boolean wrapLines, int wrapColumn)Writes the provided line to LDIF using the provided information.voidwriteModifyChangeRecord(DN dn, List<Modification> modifications)Writes a modify change record with the provided information.voidwriteModifyDNChangeRecord(DN dn, RDN newRDN, boolean deleteOldRDN, DN newSuperior)Writes a modify DN change record with the provided information.booleanwriteTemplateEntry(TemplateEntry templateEntry)Writes the provided template entry to LDIF.
-
-
-
Constructor Detail
-
LDIFWriter
public LDIFWriter(LDIFExportConfig exportConfig) throws IOException
Creates a new LDIF writer with the provided configuration.- Parameters:
exportConfig- The configuration to use for the export. It must not benull.- Throws:
IOException- If a problem occurs while opening the writer.
-
-
Method Detail
-
writeComment
public void writeComment(org.forgerock.i18n.LocalizableMessage comment, int wrapColumn) throws IOExceptionWrites the provided comment to the LDIF file, optionally wrapping near the specified column. Each line will be prefixed by the octothorpe (#) character followed by a space. If the comment should be wrapped at a specified column, then it will attempt to do so at the first whitespace character at or before that column (so it will try not wrap in the middle of a word).
This comment will be ignored by the Directory Server's LDIF reader, as well as any other compliant LDIF parsing software.- Parameters:
comment- The comment to be written. Any line breaks that it contains will be honored, and potentially new line breaks may be introduced by the wrapping process. It must not benull.wrapColumn- The column at which long lines should be wrapped, or -1 to indicate that no additional wrapping should be added. This will override the wrap column setting specified in the LDIF export configuration.- Throws:
IOException- If a problem occurs while attempting to write the comment to the LDIF file.
-
writeEntries
public boolean writeEntries(Collection<Entry> entries) throws IOException, LDIFException
Iterates over each entry contained in the map and writes out the entry in LDIF format. The main benefit of this method is that the entries can be sorted by DN and output in sorted order.- Parameters:
entries- The Map containing the entries keyed by DN.- Returns:
trueof all of the entries were written out,falseif it was not because of the export configuration.- Throws:
IOException- If a problem occurs while writing the entry to LDIF.LDIFException- If a problem occurs while trying to determine whether to include the entry in the export.
-
writeEntry
public boolean writeEntry(Entry entry) throws IOException, LDIFException
Writes the provided entry to LDIF.- Parameters:
entry- The entry to be written. It must not benull.- Returns:
trueif the entry was actually written, orfalseif it was not because of the export configuration.- Throws:
IOException- If a problem occurs while writing the entry to LDIF.LDIFException- If a problem occurs while trying to determine whether to include the entry in the export.
-
writeTemplateEntry
public boolean writeTemplateEntry(TemplateEntry templateEntry) throws IOException, LDIFException
Writes the provided template entry to LDIF.- Parameters:
templateEntry- The template entry to be written. It must not benull.- Returns:
trueif the entry was actually written, orfalseif it was not because of the export configuration.- Throws:
IOException- If a problem occurs while writing the template entry to LDIF.LDIFException- If a problem occurs while trying to determine whether to include the template entry in the export.
-
writeChangeRecord
public void writeChangeRecord(ChangeRecordEntry changeRecord) throws IOException
Writes a change record entry for the provided change record.- Parameters:
changeRecord- The change record entry to be written.- Throws:
IOException- If a problem occurs while writing the change record.
-
writeAddChangeRecord
public void writeAddChangeRecord(Entry entry) throws IOException
Writes an add change record for the provided entry. No filtering will be performed for this entry, nor will any export plugins be invoked. Further, only the user attributes will be included.- Parameters:
entry- The entry to include in the add change record. It must not benull.- Throws:
IOException- If a problem occurs while writing the add record.
-
writeDeleteChangeRecord
public void writeDeleteChangeRecord(Entry entry, boolean commentEntry) throws IOException
Writes a delete change record for the provided entry, optionally including a comment with the full entry contents. No filtering will be performed for this entry, nor will any export plugins be invoked. Further, only the user attributes will be included.- Parameters:
entry- The entry to include in the delete change record. It must not benull.commentEntry- Indicates whether to include a comment with the contents of the entry.- Throws:
IOException- If a problem occurs while writing the delete record.
-
writeModifyChangeRecord
public void writeModifyChangeRecord(DN dn, List<Modification> modifications) throws IOException
Writes a modify change record with the provided information. No filtering will be performed, nor will any export plugins be invoked.- Parameters:
dn- The DN of the entry being modified. It must not benull.modifications- The set of modifications to include in the change record. It must not benull.- Throws:
IOException- If a problem occurs while writing the modify record.
-
writeModifyDNChangeRecord
public void writeModifyDNChangeRecord(DN dn, RDN newRDN, boolean deleteOldRDN, DN newSuperior) throws IOException
Writes a modify DN change record with the provided information. No filtering will be performed, nor will any export plugins be invoked.- Parameters:
dn- The DN of the entry before the rename. It must not benull.newRDN- The new RDN for the entry. It must not benull.deleteOldRDN- Indicates whether the old RDN value should be removed from the entry.newSuperior- The new superior DN for the entry, ornullif the entry will stay below the same parent.- Throws:
IOException- If a problem occurs while writing the modify record.
-
flush
public void flush() throws IOExceptionFlushes the data written to the output stream or underlying file.- Throws:
IOException- If a problem occurs while flushing the output.
-
close
public void close() throws IOExceptionCloses the LDIF writer and the underlying output stream or file.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- If a problem occurs while closing the writer.
-
appendLDIFSeparatorAndValue
public static void appendLDIFSeparatorAndValue(StringBuilder buffer, ByteSequence valueBytes)
Appends an LDIF separator and properly-encoded form of the given value to the provided buffer. If the value is safe to include as-is, then a single colon, a single space, space, and the provided value will be appended. Otherwise, two colons, a single space, and a base64-encoded form of the value will be appended.- Parameters:
buffer- The buffer to which the information should be appended. It must not benull.valueBytes- The value to append to the buffer. It must not benull.
-
appendLDIFSeparatorAndValue
public static void appendLDIFSeparatorAndValue(StringBuilder buffer, ByteSequence valueBytes, boolean isURL, boolean isBase64)
Appends an LDIF separator and properly-encoded form of the given value to the provided buffer. If the value is safe to include as-is, then a single colon, a single space, space, and the provided value will be appended. Otherwise, two colons, a single space, and a base64-encoded form of the value will be appended.- Parameters:
buffer- The buffer to which the information should be appended. It must not benull.valueBytes- The value to append to the buffer. It must not benull.isURL- Whether the provided value is an URL value or not.isBase64- Whether the provided value is a base 64 value or not.
-
writeLDIFLine
public static void writeLDIFLine(StringBuilder line, BufferedWriter writer, boolean wrapLines, int wrapColumn) throws IOException
Writes the provided line to LDIF using the provided information.- Parameters:
line- The line of information to write. It must not benull.writer- The writer to which the data should be written. It must not benull.wrapLines- Indicates whether to wrap long lines.wrapColumn- The column at which long lines should be wrapped.- Throws:
IOException- If a problem occurs while writing the information.
-
-