Class FileOutputStreamResource

  • All Implemented Interfaces:
    org.smooks.api.delivery.ContentHandler, org.smooks.api.delivery.ordering.Consumer, org.smooks.api.lifecycle.PostExecutionLifecycle, org.smooks.api.lifecycle.PostFragmentLifecycle, org.smooks.api.resource.visitor.dom.DOMVisitBefore, org.smooks.api.resource.visitor.dom.DOMVisitor, org.smooks.api.resource.visitor.sax.ng.BeforeVisitor, org.smooks.api.resource.visitor.sax.ng.SaxNgVisitor, org.smooks.api.resource.visitor.Visitor

    public class FileOutputStreamResource
    extends org.smooks.io.AbstractOutputStreamResource
    An AbstractOutputStreamResource implementation that handles file output streams.

    Example configuration:

     <resource-config selector="order-item">
        <resource>org.smooks.io.file.FileOutputStreamResource</resource>
        <param name="resourceName">resourceName</param>
        <param name="fileNamePattern">orderitem-${order.orderId}-${order.orderItem.itemId}.xml</param>
        <param name="destinationDirectoryPattern">order-${order.orderId}</param>
        <param name="listFileNamePattern">orderitems-${order.orderId}.lst</param>
     </resource-config>
    
     Optional properties (default values shown):
        <param name="highWaterMark">200</param>
        <param name="highWaterMarkTimeout">60000</param>
     

    Description of configuration properties:

    • resourceName: the name of this resouce. Will be used to identify this resource.
    • fileNamePattern: is the pattern that will be used to generate file names. The file is created in the destinationDirectory. Supports templating.
    • listFileNamePattern: is name of the file that will contain the file names generated by this configuration. The file is created in the destinationDirectory. Supports templating.
    • destinationDirectoryPattern: is the destination directory for files created by this router. Supports templating.
    • highWaterMark: max number of output files in the destination directory at any time.
    • highWaterMarkTimeout: number of ms to wait for the system to process files in the destination directory so that the number of files drops below the highWaterMark.
    • highWaterMarkPollFrequency: number of ms to wait between checks on the High Water Mark, while waiting for it to drop.
    • closeOnCondition: An MVEL expression. If it returns true then the output stream is closed on the visitAfter event else it is kept open. If the expression is not set then output stream is closed by default.
    • append: Will append to the file specified with the 'fileNamePattern' property. This is useful for example when you want to append to a single csv file.

    When does a new file get created?
    As soon as an object tries to retrieve the Writer or the OutputStream from this OutputStreamResource and the Stream isn't open then a new file is created. Using the 'closeOnCondition' property you can control when a stream get closed. As long as the stream isn't closed, the same file is used to write too. At then end of the filter process the stream always gets closed. Nothing stays open.

    Author:
    Daniel Bevenius, maurice.zeijen@smies.com
    • Constructor Detail

      • FileOutputStreamResource

        public FileOutputStreamResource()
    • Method Detail

      • setHighWaterMarkPollFrequency

        public FileOutputStreamResource setHighWaterMarkPollFrequency​(long highWaterMarkPollFrequency)
      • setCloseOnCondition

        public void setCloseOnCondition​(String closeOnCondition)
      • initialize

        @PostConstruct
        public void initialize()
                        throws org.smooks.api.SmooksConfigException
        Throws:
        org.smooks.api.SmooksConfigException
      • closeCondition

        protected boolean closeCondition​(org.smooks.api.ExecutionContext executionContext)
        Overrides:
        closeCondition in class org.smooks.io.AbstractOutputStreamResource
      • closeResource

        protected void closeResource​(org.smooks.api.ExecutionContext executionContext)
        Overrides:
        closeResource in class org.smooks.io.AbstractOutputStreamResource
      • onPostExecution

        public void onPostExecution​(org.smooks.api.ExecutionContext executionContext)
        Specified by:
        onPostExecution in interface org.smooks.api.lifecycle.PostExecutionLifecycle
        Overrides:
        onPostExecution in class org.smooks.io.AbstractOutputStreamResource