Class LdifReader
- All Implemented Interfaces:
ResourceAwareItemReaderItemStream<org.springframework.ldap.core.LdapAttributes>,ItemReader<org.springframework.ldap.core.LdapAttributes>,ItemStream,ItemStreamReader<org.springframework.ldap.core.LdapAttributes>,org.springframework.beans.factory.InitializingBean
LdifReader is an adaptation of the FlatFileItemReader
built around an LdifParser.
Unlike the FlatFileItemReader, the LdifReader
does not require a mapper. Instead, this version of the LdifReader simply returns an LdapAttributes
object which can be consumed and manipulated as necessary by ItemProcessor or any
output service. Alternatively, the RecordMapper interface can be implemented and set in a
MappingLdifReader to map records to objects for return.
LdifReader usage is mimics that of the FlatFileItemReader
for all intensive purposes. Adjustments have been made to process records instead of lines, however. As such, the
recordsToSkip attribute indicates the number of records from the top of the file that should not be processed.
Implementations of the RecordCallbackHandler interface can be used to execute operations on those skipped records.
As with the FlatFileItemReader, the strict option differentiates
between whether or not to require the resource to exist before processing. In the case of a value set to false, a warning is logged instead of
an exception being thrown.
- Author:
- Keith Barlow
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voiddoClose()Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().protected voiddoOpen()Open resources necessary to start reading input.protected org.springframework.ldap.core.LdapAttributesdoRead()Read next item from input.voidsetRecordsToSkip(int recordsToSkip) Public setter for the number of lines to skip at the start of a file.voidsetResource(org.springframework.core.io.Resource resource) Establishes the resource that will be used as the input for the LdifReader.voidsetSkippedRecordsCallback(RecordCallbackHandler skippedRecordsCallback) RecordCallbackHandlerimplementations can be used to take action on skipped records.voidsetStrict(boolean strict) In strict mode the reader will throw an exception onAbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)if the input resource does not exist.Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, jumpToItem, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, updateMethods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.batch.item.ItemReader
readMethods inherited from interface org.springframework.batch.item.ItemStream
close, open, update
-
Constructor Details
-
LdifReader
public LdifReader()
-
-
Method Details
-
setStrict
public void setStrict(boolean strict) In strict mode the reader will throw an exception onAbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)if the input resource does not exist.- Parameters:
strict- true by default
-
setSkippedRecordsCallback
RecordCallbackHandlerimplementations can be used to take action on skipped records.- Parameters:
skippedRecordsCallback- will be called for each one of the initial skipped lines before any items are read.
-
setRecordsToSkip
public void setRecordsToSkip(int recordsToSkip) Public setter for the number of lines to skip at the start of a file. Can be used if the file contains a header without useful (column name) information, and without a comment delimiter at the beginning of the lines.- Parameters:
recordsToSkip- the number of lines to skip
-
doClose
Description copied from class:AbstractItemCountingItemStreamItemReaderClose the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().- Specified by:
doClosein classAbstractItemCountingItemStreamItemReader<org.springframework.ldap.core.LdapAttributes>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doOpen
Description copied from class:AbstractItemCountingItemStreamItemReaderOpen resources necessary to start reading input.- Specified by:
doOpenin classAbstractItemCountingItemStreamItemReader<org.springframework.ldap.core.LdapAttributes>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doRead
Description copied from class:AbstractItemCountingItemStreamItemReaderRead next item from input.- Specified by:
doReadin classAbstractItemCountingItemStreamItemReader<org.springframework.ldap.core.LdapAttributes>- Returns:
- an item or
nullif the data source is exhausted - Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
setResource
public void setResource(org.springframework.core.io.Resource resource) Establishes the resource that will be used as the input for the LdifReader.- Specified by:
setResourcein interfaceResourceAwareItemReaderItemStream<org.springframework.ldap.core.LdapAttributes>- Parameters:
resource- the resource that will be read.
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-