Package org.forgerock.opendj.ldif
Class LdifChangeRecordReader
- java.lang.Object
-
- org.forgerock.opendj.ldif.LdifChangeRecordReader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ChangeRecordReader
public final class LdifChangeRecordReader extends Object implements 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); }
-
-
Constructor Summary
Constructors Constructor Description LdifChangeRecordReader(InputStream in)
Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this change record reader if it not already closed.boolean
hasNext()
Returnstrue
if 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.ChangeRecord
readChangeRecord()
Reads the next change record, blocking if necessary until a change record is available.LdifChangeRecordReader
setExcludeAllOperationalAttributes(boolean excludeOperationalAttributes)
Specifies whether all operational attributes should be excluded from any change records that are read from LDIF.LdifChangeRecordReader
setExcludeAllUserAttributes(boolean excludeUserAttributes)
Specifies whether all user attributes should be excluded from any change records that are read from LDIF.LdifChangeRecordReader
setExcludeAttribute(AttributeDescription attributeDescription)
Excludes the named attribute from any change records that are read from LDIF.LdifChangeRecordReader
setExcludeBranch(Dn excludeBranch)
Excludes all change records which target entries beneath the named entry (inclusive) from being read from LDIF.LdifChangeRecordReader
setIncludeAttribute(AttributeDescription attributeDescription)
Ensures that the named attribute is not excluded from any change records that are read from LDIF.LdifChangeRecordReader
setIncludeBranch(Dn includeBranch)
Ensures that all change records which target entries beneath the named entry (inclusive) are read from LDIF.LdifChangeRecordReader
setRejectedLdifListener(RejectedLdifListener listener)
Sets the rejected record listener which should be notified whenever an LDIF record is skipped, malformed, or fails schema validation.LdifChangeRecordReader
setSchema(Schema schema)
Sets the schema which should be used for decoding change records that are read from LDIF.LdifChangeRecordReader
setSchemaValidationPolicy(SchemaValidationPolicy policy)
Specifies the schema validation which should be used when reading LDIF change records.
-
-
-
Constructor Detail
-
LdifChangeRecordReader
public LdifChangeRecordReader(InputStream in)
Creates a new LDIF change record reader whose source is the provided input stream.- Parameters:
in
- The input stream to use.- Throws:
NullPointerException
- Ifin
wasnull
.
-
LdifChangeRecordReader
public LdifChangeRecordReader(List<String> ldifLines)
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
- IfldifLines
wasnull
.
-
LdifChangeRecordReader
public LdifChangeRecordReader(Reader reader)
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
- Ifreader
wasnull
.
-
LdifChangeRecordReader
public LdifChangeRecordReader(String... ldifLines)
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
- IfldifLines
wasnull
.
-
-
Method Detail
-
close
public void close() throws IOException
Description copied from interface:ChangeRecordReader
Closes 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChangeRecordReader
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an unexpected IO error occurred while closing.
-
hasNext
public boolean hasNext() throws IOException
Returnstrue
if 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:
hasNext
in interfaceChangeRecordReader
- Returns:
true
if 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
public ChangeRecord readChangeRecord() throws IOException
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 anAdd
change record.- Specified by:
readChangeRecord
in 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
-true
if all operational attributes should be excluded, orfalse
otherwise.- Returns:
- A reference to this
LdifChangeRecordReader
.
-
setExcludeAllUserAttributes
public LdifChangeRecordReader setExcludeAllUserAttributes(boolean excludeUserAttributes)
Specifies whether all user attributes should be excluded from any change records that are read from LDIF. The default isfalse
.- Parameters:
excludeUserAttributes
-true
if all user attributes should be excluded, orfalse
otherwise.- Returns:
- A reference to this
LdifChangeRecordReader
.
-
setExcludeAttribute
public LdifChangeRecordReader setExcludeAttribute(AttributeDescription attributeDescription)
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
public LdifChangeRecordReader setExcludeBranch(Dn excludeBranch)
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
public LdifChangeRecordReader setIncludeAttribute(AttributeDescription attributeDescription)
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
public LdifChangeRecordReader setIncludeBranch(Dn includeBranch)
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
public LdifChangeRecordReader setRejectedLdifListener(RejectedLdifListener listener)
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_FAST
listener is used.- Parameters:
listener
- The rejected record listener.- Returns:
- A reference to this
LdifChangeRecordReader
.
-
setSchema
public LdifChangeRecordReader setSchema(Schema schema)
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
public LdifChangeRecordReader setSchemaValidationPolicy(SchemaValidationPolicy policy)
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
.
-
-