Package org.oddjob.io

Class CopyJob

java.lang.Object
org.oddjob.io.CopyJob
All Implemented Interfaces:
Serializable, Runnable

public class CopyJob extends Object implements Runnable, Serializable
See Also:

Description

A Copy job. Copy either:
  • A file from one name to another.
  • A file or files or directories to a different directory.
  • An input (from another job) to a file.
  • A file to an output.
  • An input to an output.
  • A file or input by lines to a Consumer such as a Bean Bus Destination

Example

Copy a file.
<oddjob id="this">

    <job>

        <copy to="${work.dir}">

            <from>

                <file file="${base.dir}/test/io/reference/test1.txt"/>

            </from>

        </copy>

    </job>

</oddjob>
Copy a directory.
<oddjob id="this">

    <job>

        <copy to="${work.dir}">

            <from>

                <file file="${base.dir}/test/io/reference/a"/>

            </from>

        </copy>

    </job>

</oddjob>
Copy from a file to a buffer.
<oddjob id="this">

    <job>

        <sequential>

            <jobs>

                <copy name="Copy from a file to a buffer">

                    <from>

                        <file file="${this.args[0]}/test/io/reference/test1.txt"/>

                    </from>

                    <output>

                        <identify id="buff">

                            <value>

                                <buffer/>

                            </value>

                        </identify>



                    </output>

                </copy>

                <echo id="e" name="What's in the file?">${buff}</echo>

            </jobs>

        </sequential>

    </job>

</oddjob>
Copy into a Bean Bus. The lines from the file are copied into the bus where they are mapped with a function that appends 'Foo' before writing them out in another file.
<oddjob id="oddjob">

    <job>

        <sequential>

            <jobs>

                <properties>

                    <values>

                        <value key="work.dir" value="${java.io.tmpdir}"/>

                    </values>

                </properties>

                <bus:bus xmlns:bus="oddjob:beanbus">

                    <of>

                        <copy name="Copy from a file to lines">

                            <from>

                                <file file="${oddjob.dir}/files/Lines.txt"/>

                            </from>

                        </copy>

                        <bus:map>

                            <function>

                                <value value="#{function(x) { return x + 'Foo' }}"/>

                            </function>

                        </bus:map>

                        <bus:collect>

                            <output>

                                <file file="${work.dir}/LinesFoo.txt"/>

                            </output>

                        </bus:collect>

                    </of>

                </bus:bus>

            </jobs>

        </sequential>

    </job>

</oddjob>
  • Constructor Details

    • CopyJob

      public CopyJob()
  • Method Details

    • getName

      public String getName()
      Get the name.
      Returns:
      The name.
    • setName

      public void setName(String name)
      Set the name
      Parameters:
      name - The name.
    • getFrom

      public File[] getFrom()
      Get the from file.
      Returns:
      The from file.
    • setFrom

      public void setFrom(File[] file)
      Set the From file.
      Parameters:
      file - The from file.
    • getTo

      public File getTo()
      Get the to file.
      Returns:
      The to file.
    • setTo

      public void setTo(File file)
      Set the to file.
      Parameters:
      file - The to file.
    • setInput

      public void setInput(InputStream in)
      Set the InputStream.
      Parameters:
      in - The InputStream.
    • setOutput

      public void setOutput(OutputStream out)
      Set the OutputStream.
      Parameters:
      out - The OutputStream.
    • getFilesCopied

      public int getFilesCopied()
    • getDirectoriesCopied

      public int getDirectoriesCopied()
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • getInput

      public InputStream getInput()
      Returns:
      Returns the input.
    • getOutput

      public OutputStream getOutput()
      Returns:
      Returns the output.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setConsumer

      public void setConsumer(Consumer<? super String> consumer)
    • getConsumer

      public Consumer<? super String> getConsumer()