Class LDIFEntrySource

java.lang.Object
com.unboundid.ldap.sdk.EntrySource
com.unboundid.ldif.LDIFEntrySource
All Implemented Interfaces:
Closeable, AutoCloseable

This class provides an EntrySource that will read entries from an LDIF file.

Example

The following example demonstrates the process that may be used for iterating through all entries in an LDIF file using the entry source API:
 LDIFEntrySource entrySource =
      new LDIFEntrySource(new LDIFReader(pathToLDIFFile));

 int entriesRead = 0;
 int errorsEncountered = 0;
 try
 {
   while (true)
   {
     try
     {
       Entry entry = entrySource.nextEntry();
       if (entry == null)
       {
         // There are no more entries to be read.
         break;
       }
       else
       {
         // Do something with the entry here.
         entriesRead++;
       }
     }
     catch (EntrySourceException e)
     {
       // Some kind of problem was encountered (e.g., a malformed entry
       // found in the LDIF file, or an I/O error when trying to read).  See
       // if we can continue reading entries.
       errorsEncountered++;
       if (! e.mayContinueReading())
       {
         break;
       }
     }
   }
 }
 finally
 {
   entrySource.close();
 }
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new LDAP entry source that will obtain entries from the provided LDIF reader.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Indicates that this entry source will no longer be needed and any resources associated with it may be closed.
    Retrieves the next entry from the entry source, if there is at least one remaining entry.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LDIFEntrySource

      public LDIFEntrySource(@NotNull LDIFReader ldifReader)
      Creates a new LDAP entry source that will obtain entries from the provided LDIF reader.
      Parameters:
      ldifReader - The LDIF reader from which to read entries. It must not be null.
  • Method Details

    • nextEntry

      Retrieves the next entry from the entry source, if there is at least one remaining entry. This method may block if no entries are immediately available.
      Specified by:
      nextEntry in class EntrySource
      Returns:
      The next entry from the entry source, or null if there are no more entries to retrieve.
      Throws:
      EntrySourceException - If a problem occurs while attempting to read the next entry from the entry source.
    • close

      public void close()
      Indicates that this entry source will no longer be needed and any resources associated with it may be closed. This method MUST be called if the entry source is no longer needed before all entries have been read. It MAY be called after all entries have been read with no ill effects, but this is not necessary as the entry source will have already been closed after all entries have been read.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class EntrySource