Package org.forgerock.opendj.ldif
Class LDIFChangeRecordReader
java.lang.Object
org.forgerock.opendj.ldif.LDIFChangeRecordReader
- All Implemented Interfaces:
Closeable,AutoCloseable,ChangeRecordReader
An LDIF change record reader reads change records using the LDAP Data
Interchange Format (LDIF) from a user defined source.
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 reader whose source is the provided input stream.LDIFChangeRecordReader(Reader reader) Creates a new LDIF change record reader whose source is the provided character stream reader.LDIFChangeRecordReader(String... ldifLines) Creates a new LDIF change record reader which will read lines of LDIF from the provided array of LDIF lines.LDIFChangeRecordReader(List<String> ldifLines) Creates a new LDIF change record reader which will read lines of LDIF from the provided list of LDIF lines. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this change record reader if it not already closed.booleanhasNext()Returnstrueif this reader contains another change record, blocking if necessary until either the next change record is available or the end of the stream is reached.Reads the next change record, blocking if necessary until a change record is available.setExcludeAllOperationalAttributes(boolean excludeOperationalAttributes) Specifies whether all operational attributes should be excluded from any change records that are read from LDIF.setExcludeAllUserAttributes(boolean excludeUserAttributes) Specifies whether all user attributes should be excluded from any change records that are read from LDIF.setExcludeAttribute(AttributeDescription attributeDescription) Excludes the named attribute from any change records that are read from LDIF.setExcludeBranch(DN excludeBranch) Excludes all change records which target entries beneath the named entry (inclusive) from being read from LDIF.setIncludeAttribute(AttributeDescription attributeDescription) Ensures that the named attribute is not excluded from any change records that are read from LDIF.setIncludeBranch(DN includeBranch) Ensures that all change records which target entries beneath the named entry (inclusive) are read from LDIF.setRejectedLDIFListener(RejectedLDIFListener listener) Sets the rejected record listener which should be notified whenever an LDIF record is skipped, malformed, or fails schema validation.Sets the schema which should be used for decoding change records that are read from LDIF.Specifies the schema validation which should be used when reading LDIF change records.static ChangeRecordvalueOfLDIFChangeRecord(String... ldifLines) Parses the provided array of LDIF lines as a single LDIF change record.
-
Constructor Details
-
LDIFChangeRecordReader
Creates a new LDIF change record reader whose source is the provided input stream.- Parameters:
in- The input stream to use.- Throws:
NullPointerException- Ifinwasnull.
-
LDIFChangeRecordReader
Creates a new LDIF change record reader which will read lines of LDIF from the provided list of LDIF lines.- Parameters:
ldifLines- The lines of LDIF to be read.- Throws:
NullPointerException- IfldifLineswasnull.
-
LDIFChangeRecordReader
Creates a new LDIF change record reader whose source is the provided character stream reader.- Parameters:
reader- The character stream reader to use.- Throws:
NullPointerException- Ifreaderwasnull.
-
LDIFChangeRecordReader
Creates a new LDIF change record reader which will read lines of LDIF from the provided array of LDIF lines.- Parameters:
ldifLines- The lines of LDIF to be read.- Throws:
NullPointerException- IfldifLineswasnull.
-
-
Method Details
-
valueOfLDIFChangeRecord
Parses the provided array of LDIF lines as a single LDIF change record.- Parameters:
ldifLines- The lines of LDIF to be parsed.- Returns:
- The parsed LDIF change record.
- Throws:
org.forgerock.i18n.LocalizedIllegalArgumentException- IfldifLinesdid not contain an LDIF change record, if it contained multiple change records, if contained malformed LDIF, or if the change record could not be decoded using the default schema.NullPointerException- IfldifLineswasnull.
-
close
Description copied from interface:ChangeRecordReaderCloses this change record reader if it not already closed. Note that this method does not need to be called if a previous call ofChangeRecordReader.readChangeRecord()has returnednull.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChangeRecordReader- Specified by:
closein interfaceCloseable- Throws:
IOException- If an unexpected IO error occurred while closing.
-
hasNext
Returnstrueif this reader contains another change record, blocking if necessary until either the next change record is available or the end of the stream is reached.- Specified by:
hasNextin interfaceChangeRecordReader- Returns:
trueif this reader contains another change record.- Throws:
DecodeException- If the change record could not be decoded because it was malformed.IOException- If an unexpected IO error occurred.
-
readChangeRecord
Reads the next change record, blocking if necessary until a change record is available. If the next change record does not contain a change type then it will be treated as anAddchange record.- Specified by:
readChangeRecordin interfaceChangeRecordReader- Returns:
- The next change record.
- Throws:
DecodeException- If the entry could not be decoded because it was malformed.IOException- If an unexpected IO error occurred while reading the change record.
-
setExcludeAllOperationalAttributes
public LDIFChangeRecordReader setExcludeAllOperationalAttributes(boolean excludeOperationalAttributes) Specifies whether all operational attributes should be excluded from any change records that are read from LDIF. The default isfalse.- Parameters:
excludeOperationalAttributes-trueif all operational attributes should be excluded, orfalseotherwise.- Returns:
- A reference to this
LDIFChangeRecordReader.
-
setExcludeAllUserAttributes
Specifies whether all user attributes should be excluded from any change records that are read from LDIF. The default isfalse.- Parameters:
excludeUserAttributes-trueif all user attributes should be excluded, orfalseotherwise.- Returns:
- A reference to this
LDIFChangeRecordReader.
-
setExcludeAttribute
Excludes the named attribute from any change records that are read from 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
LDIFChangeRecordReader.
-
setExcludeBranch
Excludes all change records which target entries beneath the named entry (inclusive) from being read from LDIF. By default all change records are read unless explicitly excluded or included.- Parameters:
excludeBranch- The distinguished name of the branch to be excluded.- Returns:
- A reference to this
LDIFChangeRecordReader.
-
setIncludeAttribute
Ensures that the named attribute is not excluded from any change records that are read from 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
LDIFChangeRecordReader.
-
setIncludeBranch
Ensures that all change records which target entries beneath the named entry (inclusive) are read from LDIF. By default all change records are read unless explicitly excluded or included.- Parameters:
includeBranch- The distinguished name of the branch to be included.- Returns:
- A reference to this
LDIFChangeRecordReader.
-
setRejectedLDIFListener
Sets the rejected record listener which should be notified whenever an LDIF record is skipped, malformed, or fails schema validation.By default the
RejectedLDIFListener.FAIL_FASTlistener is used.- Parameters:
listener- The rejected record listener.- Returns:
- A reference to this
LDIFChangeRecordReader.
-
setSchema
Sets the schema which should be used for decoding change records that are read from LDIF. The default schema is used if no other is specified.- Parameters:
schema- The schema which should be used for decoding change records that are read from LDIF.- Returns:
- A reference to this
LDIFChangeRecordReader.
-
setSchemaValidationPolicy
Specifies the schema validation which should be used when reading LDIF change records. If attribute value validation is enabled then all checks will be performed.Schema validation is disabled by default.
NOTE: this method copies the provided policy so changes made to it after this method has been called will have no effect.
- Parameters:
policy- The schema validation which should be used when reading LDIF change records.- Returns:
- A reference to this
LDIFChangeRecordReader.
-