Class LDIFWriter

    • 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 be null.
        Throws:
        IOException - If a problem occurs while opening the writer.
    • Method Detail

      • writeComment

        public void writeComment​(org.forgerock.i18n.LocalizableMessage comment,
                                 int wrapColumn)
                          throws IOException
        Writes 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 be null.
        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 be null.
        Returns:
        true if the entry was actually written, or false if 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 be null.
        Returns:
        true if the entry was actually written, or false if 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 be null.
        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 be null.
        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 be null.
        modifications - The set of modifications to include in the change record. It must not be null.
        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 be null.
        newRDN - The new RDN for the entry. It must not be null.
        deleteOldRDN - Indicates whether the old RDN value should be removed from the entry.
        newSuperior - The new superior DN for the entry, or null if the entry will stay below the same parent.
        Throws:
        IOException - If a problem occurs while writing the modify record.
      • flush

        public void flush()
                   throws IOException
        Flushes 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 IOException
        Closes the LDIF writer and the underlying output stream or file.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        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 be null.
        valueBytes - The value to append to the buffer. It must not be null.
      • 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 be null.
        valueBytes - The value to append to the buffer. It must not be null.
        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 be null.
        writer - The writer to which the data should be written. It must not be null.
        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.