Class FileSplitter

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.handler.AbstractMessageProducingHandler
org.springframework.integration.handler.AbstractReplyProducingMessageHandler
org.springframework.integration.splitter.AbstractMessageSplitter
org.springframework.integration.file.splitter.FileSplitter
All Implemented Interfaces:
org.reactivestreams.Subscriber<org.springframework.messaging.Message<?>>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.core.Ordered, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.Orderable, org.springframework.integration.core.MessageProducer, org.springframework.integration.handler.DiscardingMessageHandler, org.springframework.integration.handler.HeaderPropagationAware, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.TrackableComponent, org.springframework.messaging.MessageHandler, reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>

public class FileSplitter
extends org.springframework.integration.splitter.AbstractMessageSplitter
The AbstractMessageSplitter implementation to split the File Message payload to lines.

With iterator = true (defaults to true) this class produces an Iterator to process file lines on demand from Iterator.next(). Otherwise a List of all lines is returned to the to further AbstractMessageSplitter.handleRequestMessage(org.springframework.messaging.Message<?>) process.

Can accept String as file path, File, Reader or InputStream as payload type. All other types are ignored and returned to the AbstractMessageSplitter as is.

If setFirstLineAsHeader(String) is specified, the first line of the content is treated as a header and carried as a header with the provided name in the messages emitted for the remaining lines. In this case, if markers are enabled, the line count in the END marker does not include the header line and, if applySequence is true, the header is not included in the sequence.

Since:
4.1.2
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  FileSplitter.FileMarker  

    Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler

    org.springframework.integration.handler.AbstractReplyProducingMessageHandler.RequestHandler

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • Field Summary

    Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler

    messagingTemplate

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors 
    Constructor Description
    FileSplitter()
    Construct a splitter where the splitMessage(Message) method returns an iterator and the file is read line-by-line during iteration.
    FileSplitter​(boolean iterator)
    Construct a splitter where the splitMessage(Message) method returns an iterator, and the file is read line-by-line during iteration, or a list of lines from the file.
    FileSplitter​(boolean iterator, boolean markers)
    Construct a splitter where the splitMessage(Message) method returns an iterator, and the file is read line-by-line during iteration, or a list of lines from the file.
    FileSplitter​(boolean iterator, boolean markers, boolean markersJson)
    Construct a splitter where the splitMessage(Message) method returns an iterator, and the file is read line-by-line during iteration, or a list of lines from the file.
  • Method Summary

    Modifier and Type Method Description
    protected void addHeaders​(org.springframework.messaging.Message<?> message, java.util.Map<java.lang.String,​java.lang.Object> headers)  
    void setCharset​(java.nio.charset.Charset charset)
    Set the charset to be used when reading the file, when something other than the default charset is required.
    void setFirstLineAsHeader​(java.lang.String firstLineHeaderName)
    Specify the header name for the first line to be carried as a header in the messages emitted for the remaining lines.
    protected java.lang.Object splitMessage​(org.springframework.messaging.Message<?> message)  
    protected boolean willAddHeaders​(org.springframework.messaging.Message<?> message)  

    Methods inherited from class org.springframework.integration.splitter.AbstractMessageSplitter

    doInit, getComponentType, getDiscardChannel, getIntegrationPatternType, handleRequestMessage, obtainSizeIfPossible, obtainSizeIfPossible, produceOutput, setApplySequence, setDiscardChannel, setDiscardChannelName, shouldCopyRequestHeaders

    Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler

    doInvokeAdvisedRequestHandler, getBeanClassLoader, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply

    Methods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler

    addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, shouldSplitOutput, updateNotPropagatedHeaders

    Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler

    handleMessage, onComplete, onError, onNext, onSubscribe

    Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport

    buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack

    Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport

    afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface reactor.core.CoreSubscriber

    currentContext

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    getThisAs

    Methods inherited from interface org.springframework.messaging.MessageHandler

    handleMessage

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName
  • Constructor Details

    • FileSplitter

      public FileSplitter()
      Construct a splitter where the splitMessage(Message) method returns an iterator and the file is read line-by-line during iteration.
    • FileSplitter

      public FileSplitter​(boolean iterator)
      Construct a splitter where the splitMessage(Message) method returns an iterator, and the file is read line-by-line during iteration, or a list of lines from the file.
      Parameters:
      iterator - true to return an iterator, false to return a list of lines.
    • FileSplitter

      public FileSplitter​(boolean iterator, boolean markers)
      Construct a splitter where the splitMessage(Message) method returns an iterator, and the file is read line-by-line during iteration, or a list of lines from the file. When file markers are enabled (START/END) applySequence is false by default. If enabled, the markers are included in the sequence size.
      Parameters:
      iterator - true to return an iterator, false to return a list of lines.
      markers - true to emit start of file/end of file marker messages before/after the data.
      Since:
      4.1.5
    • FileSplitter

      public FileSplitter​(boolean iterator, boolean markers, boolean markersJson)
      Construct a splitter where the splitMessage(Message) method returns an iterator, and the file is read line-by-line during iteration, or a list of lines from the file. When file markers are enabled (START/END) applySequence is false by default. If enabled, the markers are included in the sequence size.
      Parameters:
      iterator - true to return an iterator, false to return a list of lines.
      markers - true to emit start of file/end of file marker messages before/after the data.
      markersJson - when true, markers are represented as JSON.
      Since:
      4.2.7
  • Method Details

    • setCharset

      public void setCharset​(@Nullable java.nio.charset.Charset charset)
      Set the charset to be used when reading the file, when something other than the default charset is required.
      Parameters:
      charset - the charset.
    • setFirstLineAsHeader

      public void setFirstLineAsHeader​(java.lang.String firstLineHeaderName)
      Specify the header name for the first line to be carried as a header in the messages emitted for the remaining lines.
      Parameters:
      firstLineHeaderName - the header name to carry first line.
      Since:
      5.0
    • splitMessage

      protected java.lang.Object splitMessage​(org.springframework.messaging.Message<?> message)
      Specified by:
      splitMessage in class org.springframework.integration.splitter.AbstractMessageSplitter
    • willAddHeaders

      protected boolean willAddHeaders​(org.springframework.messaging.Message<?> message)
      Overrides:
      willAddHeaders in class org.springframework.integration.splitter.AbstractMessageSplitter
    • addHeaders

      protected void addHeaders​(org.springframework.messaging.Message<?> message, java.util.Map<java.lang.String,​java.lang.Object> headers)
      Overrides:
      addHeaders in class org.springframework.integration.splitter.AbstractMessageSplitter