Package org.oddjob.io

Class BufferType

java.lang.Object
org.oddjob.io.BufferType
All Implemented Interfaces:
Serializable, ArooaValue, ArooaLifeAware

public class BufferType extends Object implements ArooaValue, ArooaLifeAware, Serializable
See Also:

Description

A buffer can be used to accumulate output from one or more jobs which can then be used as input to another job.

A buffer can be used wherever input or output can be specified. A job

A buffer can be initialised with text, or lines of text and will can also provide it's contents as text.

Example

Capturing the contents of a file in a buffer.
<oddjob id="this">

    <job>

        <sequential>

            <jobs>

                <variables id="v">

                    <buff>

                        <buffer/>

                    </buff>

                </variables>

                <copy id="foo">

                    <from>

                        <file file="${this.args[0]}/work/io/buffer_example.txt"/>

                    </from>

                    <output>

                        <value value="${v.buff}"/>

                    </output>

                </copy>

                <echo id="e">${v.buff}</echo>

            </jobs>

        </sequential>

    </job>

</oddjob>
Accumulate output in a buffer.
<oddjob id="this">

    <job>

        <sequential id="jobs">

            <jobs>

                <variables id="v">

                    <buff>

                        <buffer/>

                    </buff>

                </variables>

                <echo>apples

                    <output>

                        <value value="${v.buff}"/>

                    </output>

                </echo>

                <echo>oranges

                    <output>

                        <value value="${v.buff}"/>

                    </output>

                </echo>

                <echo>${v.buff}</echo>

            </jobs>

        </sequential>

    </job>

</oddjob>
Write the contents of a buffer to file. This example also shows initialising the buffer with a list.
<oddjob id="this">

    <job>

        <sequential>

            <jobs>

                <mkdir dir="${this.args[0]}/work/io"/>

                <variables id="v">

                    <buff>

                        <buffer>

                            <lines>

                                <list>

                                    <values>

                                        <value value="apples"/>

                                        <value value="oranges"/>

                                    </values>

                                </list>

                            </lines>

                        </buffer>

                    </buff>

                </variables>

                <copy>

                    <input>

                        <value value="${v.buff}"/>

                    </input>

                    <output>

                        <file file="${this.args[0]}/work/io/buffer_example.txt"/>

                    </output>

                </copy>

            </jobs>

        </sequential>

    </job>

</oddjob>
Using the contents of a buffer as lines. This also shows how a buffer can be initialised with text.
<oddjob id="this">

    <job>

        <sequential>

            <jobs>

                <variables id="v">

                    <buff>

                        <buffer>apples

oranges</buffer>

                    </buff>

                </variables>

                <foreach>

                    <values>

                        <value value="${v.buff.lines}"/>

                    </values>

                    <configuration>

                        <xml>

                            <foreach id="f">

                                <job>

                                    <echo>Line ${f.index} is ${f.current}.</echo>

                                </job>

                            </foreach>

                        </xml>

                    </configuration>

                </foreach>

            </jobs>

        </sequential>

    </job>

</oddjob>
  • Constructor Details

    • BufferType

      public BufferType()
  • Method Details

    • toInputStream

      public InputStream toInputStream()
    • toOutputStream

      public OutputStream toOutputStream()
    • setText

      public void setText(String text) throws IOException
      Parameters:
      text -
      Throws:
      IOException
      Reference Property:
      text

      Description

      The buffer as a text property. Either set the buffer contents from text or get the buffer contents as text.
      Required:
      No.
    • getText

      public String getText()
    • getLines

      public String[] getLines()
    • setLines

      public void setLines(String[] lines)
      Reference Property:
      lines

      Description

      The buffer contents as an array of lines. Either set the contents to be the array or read the contents of the buffer as an array.
      Required:
      No.
    • initialised

      public void initialised()
      Description copied from interface: ArooaLifeAware
      The configuration for the bean has been initialised. Constant properties and element properties will have been injected.
      Specified by:
      initialised in interface ArooaLifeAware
    • configured

      public void configured()
      Description copied from interface: ArooaLifeAware
      The configuration for the bean has been fully configured. Runtime properties will have been injected.
      Specified by:
      configured in interface ArooaLifeAware
    • destroy

      public void destroy()
      Description copied from interface: ArooaLifeAware
      The configuration for the bean is about to be destroyed. A bean can use this method to free resources.
      Specified by:
      destroy in interface ArooaLifeAware
    • toString

      public String toString()
      Overrides:
      toString in class Object