@NotExtensible @ThreadSafety(level=INTERFACE_NOT_THREADSAFE) public abstract class EntrySource extends java.lang.Object implements java.io.Closeable
LDAPEntrySource
class, which can be used to iterate across entries
returned from a directory server in response to a search request, and the
LDIFEntrySource
class, which can be used to
iterate across entries in an LDIF file.
close()
method MUST be called if the entry source is to
be discarded before guaranteeing that all entries have been read. The
close
method may be called after all entries have been read, but it
is not required. All entry source implementations MUST ensure that all
resources are properly released if the caller has read through all entries,
or if an error occurs that prevents the caller from continuing to read
through the entries (i.e., if nextEntry()
throws an
EntrySourceException
and the
EntrySourceException.mayContinueReading()
method returns
false
).
LDIFReader ldifReader = new LDIFReader(ldifFilePath); EntrySource entrySource = new LDIFEntrySource(ldifReader); int entriesRead = 0; int exceptionsCaught = 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 an LDIF file, or a referral returned from a directory). // See if we can continue reading entries. exceptionsCaught++; if (! e.mayContinueReading()) { break; } } } } finally { entrySource.close(); }
Constructor and Description |
---|
EntrySource() |
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Indicates that this entry source will no longer be needed and any resources
associated with it may be closed.
|
abstract Entry |
nextEntry()
Retrieves the next entry from the entry source, if there is at least one
remaining entry.
|
public EntrySource()
@Nullable public abstract Entry nextEntry() throws EntrySourceException
null
if there are
no more entries to retrieve.EntrySourceException
- If a problem occurs while attempting to read
the next entry from the entry source.public abstract void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable