@PublicAPI(stability=UNCOMMITTED, mayInstantiate=true, mayInvoke=true) public class LDIFReader extends Object implements Closeable
Modifier and Type | Field and Description |
---|---|
protected AtomicLong |
entriesRead
The number of entries that have been read by this LDIF reader, including those that were ignored because they
didn't match the criteria, and including those that were rejected because they were invalid in some way.
|
protected LDIFImportConfig |
importConfig
The import configuration that specifies what should be imported.
|
protected List<StringBuilder> |
lastEntryBodyLines
The lines that comprise the body of the last entry read.
|
protected List<StringBuilder> |
lastEntryHeaderLines
The lines that comprise the header (DN and any comments) for the last entry read.
|
protected long |
lastEntryLineNumber
The line number on which the last entry started.
|
protected PluginConfigManager |
pluginConfigManager
The plugin config manager that will be used if we are to invoke plugins on the entries as they are read.
|
Constructor and Description |
---|
LDIFReader(LDIFImportConfig importConfig)
Creates a new LDIF reader that will read information from the specified file.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this LDIF reader and the underlying file or input stream.
|
protected Entry |
createEntry(Dn entryDN,
List<StringBuilder> lines,
boolean checkSchema)
Parses the provided LDIF lines as an LDAP entry.
|
long |
getEntriesIgnored()
Retrieves the total number of entries that have been ignored so far by this LDIF reader because they did not
match the import criteria.
|
long |
getEntriesRead()
Retrieves the total number of entries read so far by this LDIF reader, including those that have been ignored or
rejected.
|
long |
getEntriesRejected()
Retrieves the total number of entries rejected so far by this LDIF reader.
|
protected void |
logToRejectWriter(List<StringBuilder> lines,
LocalizableMessage message)
Log a message to the reject writer if one is configured.
|
protected void |
logToSkipWriter(List<StringBuilder> lines,
LocalizableMessage message)
Log a message to the reject writer if one is configured.
|
ChangeRecord |
readChangeRecord(boolean defaultAdd)
Reads the next change record from the LDIF source.
|
protected Dn |
readDN(LinkedList<StringBuilder> lines)
Reads the DN of the entry from the provided list of lines.
|
Entry |
readEntry()
Reads the next entry from the LDIF source.
|
Entry |
readEntry(boolean checkSchema)
Reads the next entry from the LDIF source.
|
protected LinkedList<StringBuilder> |
readEntryLines()
Reads a set of lines from the next entry in the LDIF source.
|
void |
rejectEntry(Entry e,
LocalizableMessage message)
Log the specified entry and messages in the reject writer.
|
void |
rejectLastEntry(LocalizableMessage message)
Rejects the last entry read from the LDIF.
|
protected final LDIFImportConfig importConfig
protected List<StringBuilder> lastEntryBodyLines
protected List<StringBuilder> lastEntryHeaderLines
protected final AtomicLong entriesRead
protected long lastEntryLineNumber
protected final PluginConfigManager pluginConfigManager
public LDIFReader(LDIFImportConfig importConfig) throws IOException
importConfig
- The import configuration for this LDIF reader. It must not be null
.IOException
- If a problem occurs while opening the LDIF file for reading.public Entry readEntry() throws IOException, LDIFException
null
if the end of the LDIF data is reached.IOException
- If an I/O problem occurs while reading from the file.LDIFException
- If the information read cannot be parsed as an LDIF entry.public Entry readEntry(boolean checkSchema) throws IOException, LDIFException
checkSchema
- Indicates whether this reader should perform schema checking on the entry before returning it to the
caller. Note that some basic schema checking (like refusing multiple values for a single-valued
attribute) may always be performed.null
if the end of the LDIF data is reached.IOException
- If an I/O problem occurs while reading from the file.LDIFException
- If the information read cannot be parsed as an LDIF entry.protected Entry createEntry(Dn entryDN, List<StringBuilder> lines, boolean checkSchema) throws LDIFException
entryDN
- The parsed entry DN.lines
- The lines of LDIF.checkSchema
- Whether attributes should be validated.LDIFException
- If the attributes could not be parsed.public ChangeRecord readChangeRecord(boolean defaultAdd) throws IOException, LDIFException
defaultAdd
- Indicates whether the change type should default to "add" if none is explicitly provided.null
if the end of the LDIF data is reached.IOException
- If an I/O problem occurs while reading from the file.LDIFException
- If the information read cannot be parsed as an LDIF entry.protected LinkedList<StringBuilder> readEntryLines() throws IOException, LDIFException
IOException
- If a problem occurs while reading from the LDIF source.LDIFException
- If the information read is not valid LDIF.protected Dn readDN(LinkedList<StringBuilder> lines) throws LDIFException
lines
- The set of lines from which the DN should be read.LDIFException
- If DN is not the first element in the list (or the second after the LDIF version), or if a problem
occurs while trying to parse it.public void rejectLastEntry(LocalizableMessage message)
message
- A human-readable message providing the reason that the last entry read was not acceptable.public void rejectEntry(Entry e, LocalizableMessage message)
e
- The entry to log.message
- The message to log.public void close()
close
in interface Closeable
close
in interface AutoCloseable
public long getEntriesRead()
public long getEntriesIgnored()
public long getEntriesRejected()
protected void logToRejectWriter(List<StringBuilder> lines, LocalizableMessage message)
lines
- The set of rejected lines.message
- The associated error message.protected void logToSkipWriter(List<StringBuilder> lines, LocalizableMessage message)
lines
- The set of rejected lines.message
- The associated error message.Copyright 2010-2022 ForgeRock AS.