org.opends.server.util
Class LDIFReader

java.lang.Object
  extended by org.opends.server.util.LDIFReader

@PublicAPI(stability=UNCOMMITTED,
           mayInstantiate=true,
           mayExtend=false,
           mayInvoke=true)
public final class LDIFReader
extends java.lang.Object

This class provides the ability to read information from an LDIF file. It provides support for both standard entries and change entries (as would be used with a tool like ldapmodify).


Constructor Summary
LDIFReader(LDIFImportConfig importConfig)
          Creates a new LDIF reader that will read information from the specified file.
 
Method Summary
 void close()
          Closes this LDIF reader and the underlying file or input stream.
 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.
 long getLastEntryLineNumber()
          Retrieves the starting line number for the last entry read from the LDIF source.
 ChangeRecordEntry readChangeRecord(boolean defaultAdd)
          Reads the next change record from the LDIF source.
 Entry readEntry()
          Reads the next entry from the LDIF source.
 Entry readEntry(boolean checkSchema)
          Reads the next entry from the LDIF source.
 void rejectLastEntry(Message message)
          Rejects the last entry read from the LDIF.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LDIFReader

public LDIFReader(LDIFImportConfig importConfig)
           throws java.io.IOException
Creates a new LDIF reader that will read information from the specified file.

Parameters:
importConfig - The import configuration for this LDIF reader. It must not be null.
Throws:
java.io.IOException - If a problem occurs while opening the LDIF file for reading.
Method Detail

readEntry

public Entry readEntry()
                throws java.io.IOException,
                       LDIFException
Reads the next entry from the LDIF source.

Returns:
The next entry read from the LDIF source, or null if the end of the LDIF data is reached.
Throws:
java.io.IOException - If an I/O problem occurs while reading from the file.
LDIFException - If the information read cannot be parsed as an LDIF entry.

readEntry

public Entry readEntry(boolean checkSchema)
                throws java.io.IOException,
                       LDIFException
Reads the next entry from the LDIF source.

Parameters:
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.
Returns:
The next entry read from the LDIF source, or null if the end of the LDIF data is reached.
Throws:
java.io.IOException - If an I/O problem occurs while reading from the file.
LDIFException - If the information read cannot be parsed as an LDIF entry.

readChangeRecord

public ChangeRecordEntry readChangeRecord(boolean defaultAdd)
                                   throws java.io.IOException,
                                          LDIFException
Reads the next change record from the LDIF source.

Parameters:
defaultAdd - Indicates whether the change type should default to "add" if none is explicitly provided.
Returns:
The next change record from the LDIF source, or null if the end of the LDIF data is reached.
Throws:
java.io.IOException - If an I/O problem occurs while reading from the file.
LDIFException - If the information read cannot be parsed as an LDIF entry.

getLastEntryLineNumber

public long getLastEntryLineNumber()
Retrieves the starting line number for the last entry read from the LDIF source.

Returns:
The starting line number for the last entry read from the LDIF source.

rejectLastEntry

public void rejectLastEntry(Message message)
Rejects the last entry read from the LDIF. This method is intended for use by components that perform their own validation of entries (e.g., backends during import processing) in which the entry appeared valid to the LDIF reader but some other problem was encountered.

Parameters:
message - A human-readable message providing the reason that the last entry read was not acceptable.

close

public void close()
Closes this LDIF reader and the underlying file or input stream.


getEntriesRead

public long getEntriesRead()
Retrieves the total number of entries read so far by this LDIF reader, including those that have been ignored or rejected.

Returns:
The total number of entries read so far by this LDIF reader.

getEntriesIgnored

public 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.

Returns:
The total number of entries ignored so far by this LDIF reader.

getEntriesRejected

public long getEntriesRejected()
Retrieves the total number of entries rejected so far by this LDIF reader. This includes both entries that were rejected because of internal validation failure (e.g., they didn't conform to the defined server schema) or an external validation failure (e.g., the component using this LDIF reader didn't accept the entry because it didn't have a parent).

Returns:
The total number of entries rejected so far by this LDIF reader.