org.kohsuke.args4j.opts
Class OutputStreamOption

java.lang.Object
  extended by org.kohsuke.args4j.opts.StringOption
      extended by org.kohsuke.args4j.opts.OutputStreamOption
All Implemented Interfaces:
CmdLineOption

public class OutputStreamOption
extends StringOption

Option used as an OutputStream or Writer.

The option takes one parameter and recognize that as a File, unless the parameter is '-', which is treated as System.out.

For example, users can write "-log build.log" and you can open this file as an OutputStream, or they can write "-log -" to send it to console.

If the option is unspecified, this will create OutputStream that just discard the input.

This class can be extended to set the default output to change the interpretation of the unspecified state and "-".

Author:
Kohsuke Kawaguchi (kk@kohsuke.org)

Nested Class Summary
private  class OutputStreamOption.NullStream
           
 
Nested classes/interfaces inherited from interface org.kohsuke.args4j.CmdLineOption
CmdLineOption.Parameters
 
Field Summary
 
Fields inherited from class org.kohsuke.args4j.opts.StringOption
value
 
Constructor Summary
OutputStreamOption(java.lang.String optionName)
           
OutputStreamOption(java.lang.String optionName, java.lang.String defaultValue)
           
 
Method Summary
protected  java.io.OutputStream createConsoleStream()
          Called when the option is '-' to create the OutputStream.
protected  java.io.OutputStream createNullStream()
          Called when the option is not specified to create the default OutputStream
 java.io.OutputStream createOutputStream()
          Opens the specified file for writing.
 java.io.Writer createWriter()
          Opens the specified file for writing.
 
Methods inherited from class org.kohsuke.args4j.opts.StringOption
accepts, parseArguments
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutputStreamOption

public OutputStreamOption(java.lang.String optionName)

OutputStreamOption

public OutputStreamOption(java.lang.String optionName,
                          java.lang.String defaultValue)
Method Detail

createOutputStream

public java.io.OutputStream createOutputStream()
                                        throws java.io.IOException
Opens the specified file for writing. If the file is not specified, it returns a stream that's connected to nothing.

Throws:
java.io.IOException

createNullStream

protected java.io.OutputStream createNullStream()
                                         throws java.io.IOException
Called when the option is not specified to create the default OutputStream

Throws:
java.io.IOException

createConsoleStream

protected java.io.OutputStream createConsoleStream()
                                            throws java.io.IOException
Called when the option is '-' to create the OutputStream.

Throws:
java.io.IOException

createWriter

public java.io.Writer createWriter()
                            throws java.io.IOException
Opens the specified file for writing. If the file is not specified, it returns a stream that's connected to nothing.

Throws:
java.io.IOException


Copyright © 2003 Kohsuke Kawaguchi. All Rights Reserved.