Package org.forgerock.opendj.ldif
Class LdifEntryReader
- java.lang.Object
-
- org.forgerock.opendj.ldif.LdifEntryReader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,EntryReader
public final class LdifEntryReader extends Object implements EntryReader
An LDIF entry reader reads attribute value records (entries) using the LDAP Data Interchange Format (LDIF) from a user defined source.
-
-
Constructor Summary
Constructors Constructor Description LdifEntryReader(InputStream in)
Creates a new LDIF entry reader whose source is the provided input stream.LdifEntryReader(Reader reader)
Creates a new LDIF entry reader whose source is the provided character stream reader.LdifEntryReader(String... ldifLines)
Creates a new LDIF entry reader which will read lines of LDIF from the provided array of LDIF lines.LdifEntryReader(List<String> ldifLines)
Creates a new LDIF entry 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 entry reader if it is not already closed.boolean
hasNext()
Returnstrue
if this reader contains another entry, blocking if necessary until either the next entry is available or the end of the stream is reached.Entry
readEntry()
Reads the next entry, blocking if necessary until an entry is available.LdifEntryReader
setExcludeAllOperationalAttributes(boolean excludeOperationalAttributes)
Specifies whether all operational attributes should be excluded from any entries that are read from LDIF.LdifEntryReader
setExcludeAllUserAttributes(boolean excludeUserAttributes)
Specifies whether all user attributes should be excluded from any entries that are read from LDIF.LdifEntryReader
setExcludeAttribute(AttributeDescription attributeDescription)
Excludes the named attribute from any entries that are read from LDIF.LdifEntryReader
setExcludeBranch(Dn excludeBranch)
Excludes all entries beneath the named entry (inclusive) from being read from LDIF.LdifEntryReader
setIncludeAttribute(AttributeDescription attributeDescription)
Ensures that the named attribute is not excluded from any entries that are read from LDIF.LdifEntryReader
setIncludeBranch(Dn includeBranch)
Ensures that all entries beneath the named entry (inclusive) are read from LDIF.LdifEntryReader
setIncludeExcludeFilters(Collection<Filter> includeFilters, Collection<Filter> excludeFilters)
Sets the filters to include / exclude entries.LdifEntryReader
setRejectedLdifListener(RejectedLdifListener listener)
Sets the rejected record listener which should be notified whenever an LDIF record is skipped, malformed, or fails schema validation.LdifEntryReader
setSchema(Schema schema)
Sets the schema which should be used for decoding entries that are read from LDIF.LdifEntryReader
setSchemaValidationPolicy(SchemaValidationPolicy policy)
Specifies the schema validation which should be used when reading LDIF entry records.
-
-
-
Constructor Detail
-
LdifEntryReader
public LdifEntryReader(InputStream in)
Creates a new LDIF entry reader whose source is the provided input stream.- Parameters:
in
- The input stream to use.- Throws:
NullPointerException
- Ifin
wasnull
.
-
LdifEntryReader
public LdifEntryReader(List<String> ldifLines)
Creates a new LDIF entry 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
.
-
LdifEntryReader
public LdifEntryReader(Reader reader)
Creates a new LDIF entry reader whose source is the provided character stream reader.- Parameters:
reader
- The character stream reader to use.- Throws:
NullPointerException
- Ifreader
wasnull
.
-
LdifEntryReader
public LdifEntryReader(String... ldifLines)
Creates a new LDIF entry 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:EntryReader
Closes this entry reader if it is not already closed. Note that this method does not need to be called if a previous call ofEntryReader.readEntry()
has returnednull
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceEntryReader
- Throws:
IOException
- If an unexpected IO error occurred while closing.
-
hasNext
public boolean hasNext() throws IOException
Returnstrue
if this reader contains another entry, blocking if necessary until either the next entry is available or the end of the stream is reached.- Specified by:
hasNext
in interfaceEntryReader
- Returns:
true
if this reader contains another entry.- Throws:
DecodeException
- If the entry could not be decoded because it was malformed.IOException
- If an unexpected IO error occurred.
-
readEntry
public Entry readEntry() throws IOException
Reads the next entry, blocking if necessary until an entry is available.- Specified by:
readEntry
in interfaceEntryReader
- Returns:
- The next entry.
- Throws:
DecodeException
- If the entry could not be decoded because it was malformed.IOException
- If an unexpected IO error occurred while reading the entry.
-
setExcludeAllOperationalAttributes
public LdifEntryReader setExcludeAllOperationalAttributes(boolean excludeOperationalAttributes)
Specifies whether all operational attributes should be excluded from any entries 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
LdifEntryReader
.
-
setExcludeAllUserAttributes
public LdifEntryReader setExcludeAllUserAttributes(boolean excludeUserAttributes)
Specifies whether all user attributes should be excluded from any entries 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
LdifEntryReader
.
-
setExcludeAttribute
public LdifEntryReader setExcludeAttribute(AttributeDescription attributeDescription)
Excludes the named attribute from any entries 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
LdifEntryReader
.
-
setExcludeBranch
public LdifEntryReader setExcludeBranch(Dn excludeBranch)
Excludes all entries beneath the named entry (inclusive) from being read from 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
LdifEntryReader
.
-
setIncludeAttribute
public LdifEntryReader setIncludeAttribute(AttributeDescription attributeDescription)
Ensures that the named attribute is not excluded from any entries 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
LdifEntryReader
.
-
setIncludeBranch
public LdifEntryReader setIncludeBranch(Dn includeBranch)
Ensures that all entries beneath the named entry (inclusive) are read from 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
LdifEntryReader
.
-
setIncludeExcludeFilters
public LdifEntryReader 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
.
-
setRejectedLdifListener
public LdifEntryReader 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
LdifEntryReader
.
-
setSchema
public LdifEntryReader setSchema(Schema schema)
Sets the schema which should be used for decoding entries 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 entries that are read from LDIF.- Returns:
- A reference to this
LdifEntryReader
.
-
setSchemaValidationPolicy
public LdifEntryReader setSchemaValidationPolicy(SchemaValidationPolicy policy)
Specifies the schema validation which should be used when reading LDIF entry 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 entry records.- Returns:
- A reference to this
LdifEntryReader
.
-
-