Package com.unboundid.ldif
Class LDIFReader
java.lang.Object
com.unboundid.ldif.LDIFReader
- All Implemented Interfaces:
Closeable,AutoCloseable
@ThreadSafety(level=NOT_THREADSAFE)
public final class LDIFReader
extends Object
implements Closeable
This class provides an LDIF reader, which can be used to read and decode
entries and change records from a data source using the LDAP Data Interchange
Format as per RFC 2849.
This class is not synchronized. If multiple threads read from the LDIFReader, they must be synchronized externally.
This class is not synchronized. If multiple threads read from the LDIFReader, they must be synchronized externally.
Example
The following example iterates through all entries contained in an LDIF file and attempts to add them to a directory server:
LDIFReader ldifReader = new LDIFReader(pathToLDIFFile);
int entriesRead = 0;
int entriesAdded = 0;
int errorsEncountered = 0;
while (true)
{
Entry entry;
try
{
entry = ldifReader.readEntry();
if (entry == null)
{
// All entries have been read.
break;
}
entriesRead++;
}
catch (LDIFException le)
{
errorsEncountered++;
if (le.mayContinueReading())
{
// A recoverable error occurred while attempting to read a change
// record, at or near line number le.getLineNumber()
// The entry will be skipped, but we'll try to keep reading from the
// LDIF file.
continue;
}
else
{
// An unrecoverable error occurred while attempting to read an entry
// at or near line number le.getLineNumber()
// No further LDIF processing will be performed.
break;
}
}
catch (IOException ioe)
{
// An I/O error occurred while attempting to read from the LDIF file.
// No further LDIF processing will be performed.
errorsEncountered++;
break;
}
LDAPResult addResult;
try
{
addResult = connection.add(entry);
// If we got here, then the change should have been processed
// successfully.
entriesAdded++;
}
catch (LDAPException le)
{
// If we got here, then the change attempt failed.
addResult = le.toLDAPResult();
errorsEncountered++;
}
}
ldifReader.close();
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default buffer size (128KB) that will be used when reading from the data source. -
Constructor Summary
ConstructorsConstructorDescriptionLDIFReader(BufferedReader reader) Creates a new LDIF reader that will use the provided buffered reader to read the LDIF data.LDIFReader(BufferedReader reader, int numParseThreads) Creates a new LDIF reader that will read data from the specified buffered reader and parses the LDIF records asynchronously using the specified number of threads.LDIFReader(BufferedReader reader, int numParseThreads, LDIFReaderEntryTranslator entryTranslator) Creates a new LDIF reader that will read data from the specified buffered reader and parses the LDIF records asynchronously using the specified number of threads.LDIFReader(BufferedReader reader, int numParseThreads, LDIFReaderEntryTranslator entryTranslator, LDIFReaderChangeRecordTranslator changeRecordTranslator) Creates a new LDIF reader that will read data from the specified buffered reader and parses the LDIF records asynchronously using the specified number of threads.LDIFReader(File file) Creates a new LDIF reader that will read data from the specified file.LDIFReader(File[] files, int numParseThreads, LDIFReaderEntryTranslator entryTranslator) Creates a new LDIF reader that will read data from the specified files in the order in which they are provided and optionally parses the LDIF records asynchronously using the specified number of threads.LDIFReader(File[] files, int numParseThreads, LDIFReaderEntryTranslator entryTranslator, LDIFReaderChangeRecordTranslator changeRecordTranslator) Creates a new LDIF reader that will read data from the specified files in the order in which they are provided and optionally parses the LDIF records asynchronously using the specified number of threads.LDIFReader(File[] files, int numParseThreads, LDIFReaderEntryTranslator entryTranslator, LDIFReaderChangeRecordTranslator changeRecordTranslator, String characterSet) Creates a new LDIF reader that will read data from the specified files in the order in which they are provided and optionally parses the LDIF records asynchronously using the specified number of threads.LDIFReader(File file, int numParseThreads) Creates a new LDIF reader that will read data from the specified file and optionally parses the LDIF records asynchronously using the specified number of threads.LDIFReader(InputStream inputStream) Creates a new LDIF reader that will read data from the provided input stream.LDIFReader(InputStream inputStream, int numParseThreads) Creates a new LDIF reader that will read data from the specified stream and parses the LDIF records asynchronously using the specified number of threads.LDIFReader(InputStream inputStream, int numParseThreads, LDIFReaderEntryTranslator entryTranslator) Creates a new LDIF reader that will read data from the specified stream and parses the LDIF records asynchronously using the specified number of threads.LDIFReader(InputStream inputStream, int numParseThreads, LDIFReaderEntryTranslator entryTranslator, LDIFReaderChangeRecordTranslator changeRecordTranslator) Creates a new LDIF reader that will read data from the specified stream and parses the LDIF records asynchronously using the specified number of threads.LDIFReader(InputStream inputStream, int numParseThreads, LDIFReaderEntryTranslator entryTranslator, LDIFReaderChangeRecordTranslator changeRecordTranslator, String characterSet) Creates a new LDIF reader that will read data from the specified stream and parses the LDIF records asynchronously using the specified number of threads.LDIFReader(String path) Creates a new LDIF reader that will read data from the specified file.LDIFReader(String path, int numParseThreads) Creates a new LDIF reader that will read data from the specified file and parses the LDIF records asynchronously using the specified number of threads. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this LDIF reader and the underlying LDIF source.static LDIFChangeRecorddecodeChangeRecord(boolean ignoreDuplicateValues, Schema schema, boolean defaultAdd, String... ldifLines) Decodes the provided set of LDIF lines as an LDIF change record.static LDIFChangeRecorddecodeChangeRecord(boolean ignoreDuplicateValues, TrailingSpaceBehavior trailingSpaceBehavior, Schema schema, boolean defaultAdd, String... ldifLines) Decodes the provided set of LDIF lines as an LDIF change record.static LDIFChangeRecorddecodeChangeRecord(boolean defaultAdd, String... ldifLines) Decodes the provided set of LDIF lines as an LDIF change record.static LDIFChangeRecorddecodeChangeRecord(String... ldifLines) Decodes the provided set of LDIF lines as an LDIF change record.static EntrydecodeEntry(boolean ignoreDuplicateValues, Schema schema, String... ldifLines) Decodes the provided set of LDIF lines as an entry.static EntrydecodeEntry(boolean ignoreDuplicateValues, TrailingSpaceBehavior trailingSpaceBehavior, Schema schema, String... ldifLines) Decodes the provided set of LDIF lines as an entry.static EntrydecodeEntry(String... ldifLines) Decodes the provided set of LDIF lines as an entry.static LDIFRecorddecodeLDIFRecord(DuplicateValueBehavior duplicateValueBehavior, TrailingSpaceBehavior trailingSpaceBehavior, Schema schema, String... ldifLines) Decodes the provided set of lines as an LDIF record.static LDIFRecorddecodeLDIFRecord(String... ldifLines) Decodes the provided set of lines as an LDIF record.Retrieves the behavior that should be exhibited if the LDIF reader encounters an entry with duplicate values.Retrieves the base path that will be prepended to relative paths in order to obtain an absolute path.Retrieves the schema that will be used when reading LDIF records, if defined.Retrieves the behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces.booleanDeprecated.Reads an LDIF change record from the LDIF source.readChangeRecord(boolean defaultAdd) Reads an LDIF change record from the LDIF source.readEntries(File file) Reads entries from the specified LDIF file and returns them as aList.readEntries(InputStream inputStream) Reads and decodes LDIF entries from the provided input stream and returns them as aList.readEntries(String path) Reads entries from the LDIF file with the specified path and returns them as aList.Reads an entry from the LDIF source.Reads a record from the LDIF source.voidsetDuplicateValueBehavior(DuplicateValueBehavior duplicateValueBehavior) Specifies the behavior that should be exhibited if the LDIF reader encounters an entry with duplicate values.voidsetIgnoreDuplicateValues(boolean ignoreDuplicateValues) Deprecated.Use thesetDuplicateValueBehavior(com.unboundid.ldif.DuplicateValueBehavior)method instead.voidsetRelativeBasePath(File relativeBasePath) Specifies the base path that will be prepended to relative paths in order to obtain an absolute path.voidsetRelativeBasePath(String relativeBasePath) Specifies the base path that will be prepended to relative paths in order to obtain an absolute path.voidSpecifies the schema that should be used when reading LDIF records.voidsetStripTrailingSpaces(boolean stripTrailingSpaces) Deprecated.Use thesetTrailingSpaceBehavior(com.unboundid.ldif.TrailingSpaceBehavior)method instead.static voidsetSupportControls(boolean supportControls) Specifies whether the LDIF reader will attempt to handle LDAP controls contained in LDIF records.voidsetTrailingSpaceBehavior(TrailingSpaceBehavior trailingSpaceBehavior) Specifies the behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces.booleanDeprecated.Use thegetTrailingSpaceBehavior()method instead.static booleanIndicates whether the LDIF reader will attempt to handle LDAP controls contained in LDIF records.
-
Field Details
-
DEFAULT_BUFFER_SIZE
The default buffer size (128KB) that will be used when reading from the data source.- See Also:
-
-
Constructor Details
-
LDIFReader
Creates a new LDIF reader that will read data from the specified file.- Parameters:
path- The path to the file from which the data is to be read. It must not benull.- Throws:
IOException- If a problem occurs while opening the file for reading.
-
LDIFReader
Creates a new LDIF reader that will read data from the specified file and parses the LDIF records asynchronously using the specified number of threads.- Parameters:
path- The path to the file from which the data is to be read. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.- Throws:
IOException- If a problem occurs while opening the file for reading.- See Also:
-
LDIFReader
Creates a new LDIF reader that will read data from the specified file.- Parameters:
file- The file from which the data is to be read. It must not benull.- Throws:
IOException- If a problem occurs while opening the file for reading.
-
LDIFReader
Creates a new LDIF reader that will read data from the specified file and optionally parses the LDIF records asynchronously using the specified number of threads.- Parameters:
file- The file from which the data is to be read. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.- Throws:
IOException- If a problem occurs while opening the file for reading.
-
LDIFReader
public LDIFReader(@NotNull File[] files, int numParseThreads, @Nullable LDIFReaderEntryTranslator entryTranslator) throws IOException Creates a new LDIF reader that will read data from the specified files in the order in which they are provided and optionally parses the LDIF records asynchronously using the specified number of threads.- Parameters:
files- The files from which the data is to be read. It must not benullor empty.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.entryTranslator- The LDIFReaderEntryTranslator to apply to entries before they are returned. This is normallynull, which causes entries to be returned unaltered. This is particularly useful when parsing the input file in parallel because the entry translation is also done in parallel.- Throws:
IOException- If a problem occurs while opening the file for reading.
-
LDIFReader
public LDIFReader(@NotNull File[] files, int numParseThreads, @Nullable LDIFReaderEntryTranslator entryTranslator, @Nullable LDIFReaderChangeRecordTranslator changeRecordTranslator) throws IOException Creates a new LDIF reader that will read data from the specified files in the order in which they are provided and optionally parses the LDIF records asynchronously using the specified number of threads.- Parameters:
files- The files from which the data is to be read. It must not benullor empty.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.entryTranslator- The LDIFReaderEntryTranslator to apply to entries before they are returned. This is normallynull, which causes entries to be returned unaltered. This is particularly useful when parsing the input file in parallel because the entry translation is also done in parallel.changeRecordTranslator- The LDIFReaderChangeRecordTranslator to apply to change records before they are returned. This is normallynull, which causes change records to be returned unaltered. This is particularly useful when parsing the input file in parallel because the change record translation is also done in parallel.- Throws:
IOException- If a problem occurs while opening the file for reading.
-
LDIFReader
public LDIFReader(@NotNull File[] files, int numParseThreads, @Nullable LDIFReaderEntryTranslator entryTranslator, @Nullable LDIFReaderChangeRecordTranslator changeRecordTranslator, @NotNull String characterSet) throws IOException Creates a new LDIF reader that will read data from the specified files in the order in which they are provided and optionally parses the LDIF records asynchronously using the specified number of threads.- Parameters:
files- The files from which the data is to be read. It must not benullor empty.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.entryTranslator- The LDIFReaderEntryTranslator to apply to entries before they are returned. This is normallynull, which causes entries to be returned unaltered. This is particularly useful when parsing the input file in parallel because the entry translation is also done in parallel.changeRecordTranslator- The LDIFReaderChangeRecordTranslator to apply to change records before they are returned. This is normallynull, which causes change records to be returned unaltered. This is particularly useful when parsing the input file in parallel because the change record translation is also done in parallel.characterSet- The character set to use when reading from the input stream. It must not benull.- Throws:
IOException- If a problem occurs while opening the file for reading.
-
LDIFReader
Creates a new LDIF reader that will read data from the provided input stream.- Parameters:
inputStream- The input stream from which the data is to be read. It must not benull.
-
LDIFReader
Creates a new LDIF reader that will read data from the specified stream and parses the LDIF records asynchronously using the specified number of threads.- Parameters:
inputStream- The input stream from which the data is to be read. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.- See Also:
-
LDIFReader
public LDIFReader(@NotNull InputStream inputStream, int numParseThreads, @Nullable LDIFReaderEntryTranslator entryTranslator) Creates a new LDIF reader that will read data from the specified stream and parses the LDIF records asynchronously using the specified number of threads.- Parameters:
inputStream- The input stream from which the data is to be read. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.entryTranslator- The LDIFReaderEntryTranslator to apply to read entries before they are returned. This is normallynull, which causes entries to be returned unaltered. This is particularly useful when parsing the input file in parallel because the entry translation is also done in parallel.- See Also:
-
LDIFReader
public LDIFReader(@NotNull InputStream inputStream, int numParseThreads, @Nullable LDIFReaderEntryTranslator entryTranslator, @Nullable LDIFReaderChangeRecordTranslator changeRecordTranslator) Creates a new LDIF reader that will read data from the specified stream and parses the LDIF records asynchronously using the specified number of threads.- Parameters:
inputStream- The input stream from which the data is to be read. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.entryTranslator- The LDIFReaderEntryTranslator to apply to entries before they are returned. This is normallynull, which causes entries to be returned unaltered. This is particularly useful when parsing the input file in parallel because the entry translation is also done in parallel.changeRecordTranslator- The LDIFReaderChangeRecordTranslator to apply to change records before they are returned. This is normallynull, which causes change records to be returned unaltered. This is particularly useful when parsing the input file in parallel because the change record translation is also done in parallel.- See Also:
-
LDIFReader
public LDIFReader(@NotNull InputStream inputStream, int numParseThreads, @Nullable LDIFReaderEntryTranslator entryTranslator, @Nullable LDIFReaderChangeRecordTranslator changeRecordTranslator, @NotNull String characterSet) Creates a new LDIF reader that will read data from the specified stream and parses the LDIF records asynchronously using the specified number of threads.- Parameters:
inputStream- The input stream from which the data is to be read. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.entryTranslator- The LDIFReaderEntryTranslator to apply to entries before they are returned. This is normallynull, which causes entries to be returned unaltered. This is particularly useful when parsing the input file in parallel because the entry translation is also done in parallel.changeRecordTranslator- The LDIFReaderChangeRecordTranslator to apply to change records before they are returned. This is normallynull, which causes change records to be returned unaltered. This is particularly useful when parsing the input file in parallel because the change record translation is also done in parallel.characterSet- The character set to use when reading from the input stream. It must not benull.- See Also:
-
LDIFReader
Creates a new LDIF reader that will use the provided buffered reader to read the LDIF data. The encoding of the underlying Reader must be set to "UTF-8" as required by RFC 2849.- Parameters:
reader- The buffered reader that will be used to read the LDIF data. It must not benull.
-
LDIFReader
Creates a new LDIF reader that will read data from the specified buffered reader and parses the LDIF records asynchronously using the specified number of threads. The encoding of the underlying Reader must be set to "UTF-8" as required by RFC 2849.- Parameters:
reader- The buffered reader that will be used to read the LDIF data. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.- See Also:
-
LDIFReader
public LDIFReader(@NotNull BufferedReader reader, int numParseThreads, @Nullable LDIFReaderEntryTranslator entryTranslator) Creates a new LDIF reader that will read data from the specified buffered reader and parses the LDIF records asynchronously using the specified number of threads. The encoding of the underlying Reader must be set to "UTF-8" as required by RFC 2849.- Parameters:
reader- The buffered reader that will be used to read the LDIF data. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file. This should only be set to greater than zero when performance analysis has demonstrated that reading and parsing the LDIF is a bottleneck. The default synchronous processing is normally fast enough. There is little benefit in passing in a value greater than four (unless there is an LDIFReaderEntryTranslator that does time-consuming processing). A value of zero implies the default behavior of reading and parsing LDIF records synchronously when one of the read methods is called.entryTranslator- The LDIFReaderEntryTranslator to apply to read entries before they are returned. This is normallynull, which causes entries to be returned unaltered. This is particularly useful when parsing the input file in parallel because the entry translation is also done in parallel.
-
LDIFReader
public LDIFReader(@NotNull BufferedReader reader, int numParseThreads, @Nullable LDIFReaderEntryTranslator entryTranslator, @Nullable LDIFReaderChangeRecordTranslator changeRecordTranslator) Creates a new LDIF reader that will read data from the specified buffered reader and parses the LDIF records asynchronously using the specified number of threads. The encoding of the underlying Reader must be set to "UTF-8" as required by RFC 2849.- Parameters:
reader- The buffered reader that will be used to read the LDIF data. It must not benull.numParseThreads- If this value is greater than zero, then the specified number of threads will be used to asynchronously read and parse the LDIF file.entryTranslator- The LDIFReaderEntryTranslator to apply to entries before they are returned. This is normallynull, which causes entries to be returned unaltered. This is particularly useful when parsing the input file in parallel because the entry translation is also done in parallel.changeRecordTranslator- The LDIFReaderChangeRecordTranslator to apply to change records before they are returned. This is normallynull, which causes change records to be returned unaltered. This is particularly useful when parsing the input file in parallel because the change record translation is also done in parallel.
-
-
Method Details
-
readEntries
@NotNull public static List<Entry> readEntries(@NotNull String path) throws IOException, LDIFException Reads entries from the LDIF file with the specified path and returns them as aList. This is a convenience method that should only be used for data sets that are small enough so that running out of memory isn't a concern.- Parameters:
path- The path to the LDIF file containing the entries to be read.- Returns:
- A list of the entries read from the given LDIF file.
- Throws:
IOException- If a problem occurs while attempting to read data from the specified file.LDIFException- If a problem is encountered while attempting to decode data read as LDIF.
-
readEntries
@NotNull public static List<Entry> readEntries(@NotNull File file) throws IOException, LDIFException Reads entries from the specified LDIF file and returns them as aList. This is a convenience method that should only be used for data sets that are small enough so that running out of memory isn't a concern.- Parameters:
file- A reference to the LDIF file containing the entries to be read.- Returns:
- A list of the entries read from the given LDIF file.
- Throws:
IOException- If a problem occurs while attempting to read data from the specified file.LDIFException- If a problem is encountered while attempting to decode data read as LDIF.
-
readEntries
@NotNull public static List<Entry> readEntries(@NotNull InputStream inputStream) throws IOException, LDIFException Reads and decodes LDIF entries from the provided input stream and returns them as aList. This is a convenience method that should only be used for data sets that are small enough so that running out of memory isn't a concern.- Parameters:
inputStream- The input stream from which the entries should be read. The input stream will be closed before returning.- Returns:
- A list of the entries read from the given input stream.
- Throws:
IOException- If a problem occurs while attempting to read data from the input stream.LDIFException- If a problem is encountered while attempting to decode data read as LDIF.
-
close
Closes this LDIF reader and the underlying LDIF source.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- If a problem occurs while closing the underlying LDIF source.
-
ignoreDuplicateValues
Deprecated.Use thegetDuplicateValueBehavior()method instead.Indicates whether to ignore any duplicate values encountered while reading LDIF records.- Returns:
trueif duplicate values should be ignored, orfalseif any LDIF records containing duplicate values should be rejected.
-
setIgnoreDuplicateValues
Deprecated.Use thesetDuplicateValueBehavior(com.unboundid.ldif.DuplicateValueBehavior)method instead.Specifies whether to ignore any duplicate values encountered while reading LDIF records.- Parameters:
ignoreDuplicateValues- Indicates whether to ignore duplicate attribute values encountered while reading LDIF records.
-
getDuplicateValueBehavior
Retrieves the behavior that should be exhibited if the LDIF reader encounters an entry with duplicate values.- Returns:
- The behavior that should be exhibited if the LDIF reader encounters an entry with duplicate values.
-
setDuplicateValueBehavior
Specifies the behavior that should be exhibited if the LDIF reader encounters an entry with duplicate values.- Parameters:
duplicateValueBehavior- The behavior that should be exhibited if the LDIF reader encounters an entry with duplicate values.
-
stripTrailingSpaces
Deprecated.Use thegetTrailingSpaceBehavior()method instead.Indicates whether to strip off any illegal trailing spaces that may appear in LDIF records (e.g., after an entry DN or attribute value). The LDIF specification strongly recommends that any value which legitimately contains trailing spaces be base64-encoded, and any spaces which appear after the end of non-base64-encoded values may therefore be considered invalid. If any such trailing spaces are encountered in an LDIF record and they are not to be stripped, then anLDIFExceptionwill be thrown for that record.
Note that this applies only to spaces after the end of a value, and not to spaces which may appear at the end of a line for a value that is wrapped and continued on the next line.- Returns:
trueif illegal trailing spaces should be stripped off, orfalseif LDIF records containing illegal trailing spaces should be rejected.
-
setStripTrailingSpaces
Deprecated.Use thesetTrailingSpaceBehavior(com.unboundid.ldif.TrailingSpaceBehavior)method instead.Specifies whether to strip off any illegal trailing spaces that may appear in LDIF records (e.g., after an entry DN or attribute value). The LDIF specification strongly recommends that any value which legitimately contains trailing spaces be base64-encoded, and any spaces which appear after the end of non-base64-encoded values may therefore be considered invalid. If any such trailing spaces are encountered in an LDIF record and they are not to be stripped, then anLDIFExceptionwill be thrown for that record.
Note that this applies only to spaces after the end of a value, and not to spaces which may appear at the end of a line for a value that is wrapped and continued on the next line.- Parameters:
stripTrailingSpaces- Indicates whether to strip off any illegal trailing spaces, orfalseif LDIF records containing them should be rejected.
-
getTrailingSpaceBehavior
Retrieves the behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces. The LDIF specification strongly recommends that any value which legitimately contains trailing spaces be base64-encoded, but the LDAP SDK LDIF parser may be configured to automatically strip these spaces, to preserve them, or to reject any entry or change record containing them.- Returns:
- The behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces.
-
setTrailingSpaceBehavior
Specifies the behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces. The LDIF specification strongly recommends that any value which legitimately contains trailing spaces be base64-encoded, but the LDAP SDK LDIF parser may be configured to automatically strip these spaces, to preserve them, or to reject any entry or change record containing them.- Parameters:
trailingSpaceBehavior- The behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces.
-
supportControls
Indicates whether the LDIF reader will attempt to handle LDAP controls contained in LDIF records. See the documentation for thesetSupportControls(boolean)method for a more complete explanation.- Returns:
trueif the LDIF reader will attempt to handle controls contained in LDIF records, orfalseif it will not and they will be treated as regular attributes.
-
setSupportControls
Specifies whether the LDIF reader will attempt to handle LDAP controls contained in LDIF records. By default, the LDAP SDK will handle controls in accordance with RFC 2849, so that if the first unwrapped line after the DN starts with "control:", then that record will be assumed to be an LDIF change record that contains one or more LDAP controls. However, this can potentially cause a problem in one corner case: the case in which an LDIF record represents an entry in which the first attribute in the entry is named "control", and when you're either reading a generic LDIF record or you're reading an LDIF change record withdefaultAddset totrue. In such case, the LDIF reader would assume that the "control" attribute is trying to specify an LDAP control, and it would either throw an exception if it can't parse the value as a control, or it would return an LDIF add change record without the "control" attribute but with an LDAP control. Calling this method with a value offalsewill disable the LDIF reader's support for controls so that any record in which the unwrapped line immediately following the DN starts with "control:" will be treated as specifying an attribute named "control" rather than an LDAP control.- Parameters:
supportControls- Specifies whether the LDIF reader will attempt to handle LDAP controls contained in LDIF records.
-
getRelativeBasePath
Retrieves the base path that will be prepended to relative paths in order to obtain an absolute path. This will only be used for "file:" URLs that have paths which do not begin with a slash.- Returns:
- The base path that will be prepended to relative paths in order to obtain an absolute path.
-
setRelativeBasePath
Specifies the base path that will be prepended to relative paths in order to obtain an absolute path. This will only be used for "file:" URLs that have paths which do not begin with a space.- Parameters:
relativeBasePath- The base path that will be prepended to relative paths in order to obtain an absolute path.
-
setRelativeBasePath
Specifies the base path that will be prepended to relative paths in order to obtain an absolute path. This will only be used for "file:" URLs that have paths which do not begin with a space.- Parameters:
relativeBasePath- The base path that will be prepended to relative paths in order to obtain an absolute path.
-
getSchema
Retrieves the schema that will be used when reading LDIF records, if defined.- Returns:
- The schema that will be used when reading LDIF records, or
nullif no schema should be used and all attributes should be treated as case-insensitive strings.
-
setSchema
Specifies the schema that should be used when reading LDIF records.- Parameters:
schema- The schema that should be used when reading LDIF records, ornullif no schema should be used and all attributes should be treated as case-insensitive strings.
-
readLDIFRecord
Reads a record from the LDIF source. It may be either an entry or an LDIF change record.- Returns:
- The record read from the LDIF source, or
nullif there are no more entries to be read. - Throws:
IOException- If a problem occurs while trying to read from the LDIF source.LDIFException- If the data read could not be parsed as an entry or an LDIF change record.
-
decodeLDIFRecord
@NotNull public static LDIFRecord decodeLDIFRecord(@NotNull String... ldifLines) throws LDIFException Decodes the provided set of lines as an LDIF record. It may be either an entry or an LDIF change record.- Parameters:
ldifLines- The set of lines that comprise the LDIF representation of the entry or change record. It must not benullor empty.- Returns:
- The decoded LDIF entry or change record.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as an LDIF record.
-
decodeLDIFRecord
@NotNull public static LDIFRecord decodeLDIFRecord(@NotNull DuplicateValueBehavior duplicateValueBehavior, @NotNull TrailingSpaceBehavior trailingSpaceBehavior, @Nullable Schema schema, @NotNull String... ldifLines) throws LDIFException Decodes the provided set of lines as an LDIF record. It may be either an entry or an LDIF change record.- Parameters:
duplicateValueBehavior- The behavior that should be exhibited when encountering LDIF records that have duplicate attribute values. It must not benull.trailingSpaceBehavior- The behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces. It must not benull.schema- The schema to use when processing the change record, ornullif no schema should be used and all values should be treated as case-insensitive strings.ldifLines- The set of lines that comprise the LDIF representation of the entry or change record. It must not benullor empty.- Returns:
- The decoded LDIF entry or change record.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as an LDIF record.
-
readEntry
Reads an entry from the LDIF source.- Returns:
- The entry read from the LDIF source, or
nullif there are no more entries to be read. - Throws:
IOException- If a problem occurs while attempting to read from the LDIF source.LDIFException- If the data read could not be parsed as an entry.
-
readChangeRecord
Reads an LDIF change record from the LDIF source. The LDIF record must have a changetype.- Returns:
- The change record read from the LDIF source, or
nullif there are no more records to be read. - Throws:
IOException- If a problem occurs while attempting to read from the LDIF source.LDIFException- If the data read could not be parsed as an LDIF change record.
-
readChangeRecord
@Nullable public LDIFChangeRecord readChangeRecord(boolean defaultAdd) throws IOException, LDIFException Reads an LDIF change record from the LDIF source. Optionally, if the LDIF record does not have a changetype, then it may be assumed to be an add change record.- Parameters:
defaultAdd- Indicates whether an LDIF record not containing a changetype should be retrieved as an add change record. If this isfalseand the record read does not include a changetype, then anLDIFExceptionwill be thrown.- Returns:
- The change record read from the LDIF source, or
nullif there are no more records to be read. - Throws:
IOException- If a problem occurs while attempting to read from the LDIF source.LDIFException- If the data read could not be parsed as an LDIF change record.
-
decodeEntry
Decodes the provided set of LDIF lines as an entry. The provided set of lines must contain exactly one entry. Long lines may be wrapped as per the LDIF specification, and it is acceptable to have one or more blank lines following the entry. A default trailing space behavior ofTrailingSpaceBehavior.REJECTwill be used.- Parameters:
ldifLines- The set of lines that comprise the LDIF representation of the entry. It must not benullor empty.- Returns:
- The entry read from LDIF.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as an entry.
-
decodeEntry
@NotNull public static Entry decodeEntry(boolean ignoreDuplicateValues, @Nullable Schema schema, @NotNull String... ldifLines) throws LDIFException Decodes the provided set of LDIF lines as an entry. The provided set of lines must contain exactly one entry. Long lines may be wrapped as per the LDIF specification, and it is acceptable to have one or more blank lines following the entry. A default trailing space behavior ofTrailingSpaceBehavior.REJECTwill be used.- Parameters:
ignoreDuplicateValues- Indicates whether to ignore duplicate attribute values encountered while parsing.schema- The schema to use when parsing the record, if applicable.ldifLines- The set of lines that comprise the LDIF representation of the entry. It must not benullor empty.- Returns:
- The entry read from LDIF.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as an entry.
-
decodeEntry
@NotNull public static Entry decodeEntry(boolean ignoreDuplicateValues, @NotNull TrailingSpaceBehavior trailingSpaceBehavior, @Nullable Schema schema, @NotNull String... ldifLines) throws LDIFException Decodes the provided set of LDIF lines as an entry. The provided set of lines must contain exactly one entry. Long lines may be wrapped as per the LDIF specification, and it is acceptable to have one or more blank lines following the entry.- Parameters:
ignoreDuplicateValues- Indicates whether to ignore duplicate attribute values encountered while parsing.trailingSpaceBehavior- The behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces. It must not benull.schema- The schema to use when parsing the record, if applicable.ldifLines- The set of lines that comprise the LDIF representation of the entry. It must not benullor empty.- Returns:
- The entry read from LDIF.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as an entry.
-
decodeChangeRecord
@NotNull public static LDIFChangeRecord decodeChangeRecord(@NotNull String... ldifLines) throws LDIFException Decodes the provided set of LDIF lines as an LDIF change record. The provided set of lines must contain exactly one change record and it must include a changetype. Long lines may be wrapped as per the LDIF specification, and it is acceptable to have one or more blank lines following the entry.- Parameters:
ldifLines- The set of lines that comprise the LDIF representation of the change record. It must not benullor empty.- Returns:
- The change record read from LDIF.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as a change record.
-
decodeChangeRecord
@NotNull public static LDIFChangeRecord decodeChangeRecord(boolean defaultAdd, @NotNull String... ldifLines) throws LDIFException Decodes the provided set of LDIF lines as an LDIF change record. The provided set of lines must contain exactly one change record. Long lines may be wrapped as per the LDIF specification, and it is acceptable to have one or more blank lines following the entry.- Parameters:
defaultAdd- Indicates whether an LDIF record not containing a changetype should be retrieved as an add change record. If this isfalseand the record read does not include a changetype, then anLDIFExceptionwill be thrown.ldifLines- The set of lines that comprise the LDIF representation of the change record. It must not benullor empty.- Returns:
- The change record read from LDIF.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as a change record.
-
decodeChangeRecord
@NotNull public static LDIFChangeRecord decodeChangeRecord(boolean ignoreDuplicateValues, @Nullable Schema schema, boolean defaultAdd, @NotNull String... ldifLines) throws LDIFException Decodes the provided set of LDIF lines as an LDIF change record. The provided set of lines must contain exactly one change record. Long lines may be wrapped as per the LDIF specification, and it is acceptable to have one or more blank lines following the entry.- Parameters:
ignoreDuplicateValues- Indicates whether to ignore duplicate attribute values encountered while parsing.schema- The schema to use when processing the change record, ornullif no schema should be used and all values should be treated as case-insensitive strings.defaultAdd- Indicates whether an LDIF record not containing a changetype should be retrieved as an add change record. If this isfalseand the record read does not include a changetype, then anLDIFExceptionwill be thrown.ldifLines- The set of lines that comprise the LDIF representation of the change record. It must not benullor empty.- Returns:
- The change record read from LDIF.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as a change record.
-
decodeChangeRecord
@NotNull public static LDIFChangeRecord decodeChangeRecord(boolean ignoreDuplicateValues, @NotNull TrailingSpaceBehavior trailingSpaceBehavior, @Nullable Schema schema, boolean defaultAdd, @NotNull String... ldifLines) throws LDIFException Decodes the provided set of LDIF lines as an LDIF change record. The provided set of lines must contain exactly one change record. Long lines may be wrapped as per the LDIF specification, and it is acceptable to have one or more blank lines following the entry.- Parameters:
ignoreDuplicateValues- Indicates whether to ignore duplicate attribute values encountered while parsing.trailingSpaceBehavior- The behavior that should be exhibited when encountering attribute values which are not base64-encoded but contain trailing spaces. It must not benull.schema- The schema to use when processing the change record, ornullif no schema should be used and all values should be treated as case-insensitive strings.defaultAdd- Indicates whether an LDIF record not containing a changetype should be retrieved as an add change record. If this isfalseand the record read does not include a changetype, then anLDIFExceptionwill be thrown.ldifLines- The set of lines that comprise the LDIF representation of the change record. It must not benullor empty.- Returns:
- The change record read from LDIF.
- Throws:
LDIFException- If the provided LDIF data cannot be decoded as a change record.
-
getDuplicateValueBehavior()method instead.