JAPI 0.9.0
Yet another Java API
API Documentation

net.sf.japi.io
Class ARGVInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.SequenceInputStream
          extended by net.sf.japi.io.ARGVInputStream
All Implemented Interfaces:
Closeable

public class ARGVInputStream
extends SequenceInputStream

An ARGV InputStream, behaving similar as <ARGV> in Perl. Just to make life a bit less painful to Perl programmers that were reborn as Java programmers.

Don't rely on this class being a subclass of SequenceInputStream. That is subject to change.

An ARGVInputStream provides sequential access to one or more files. To create an ARGVInputStream that is just a synonym on System.in, just pass an empty String array to its constructor. To create an ARGVInputStream that sequentially accesss one file after another (similar as <ARGV> does in Perl), pass an array with the desired filenames to its constructor.

Errors that happen due to files that cannot be opened are always reported to System.err and otherwise silently ignored, i.e. not reported to the main program.

Usually, you'd use ARGVInputStream like this:

 // Cat in a similar way the UNIX command cat works like
 import java.io.IOException;
 import net.sf.japi.io.ARGVInputStream;
 import static net.sf.japi.io.IOHelper.copy;

 public class Cat {
     public static void main(final String... args) {
         try {
             copy(new ARGVInputStream(args), System.out);
         } catch (final IOException e) {
             System.err.println(e);
         }
     }
 }
 
Internally this class uses ARGVEnumeration to sequentially access the Stream elements of ARGV.

Author:
Christian Hujer
See Also:
ARGVEnumeration
Notes:
it is not required to invoke SequenceInputStream.close().

Constructor Summary
ARGVInputStream(String... args)
          Create an ARGVInputStream.
 
Method Summary
 
Methods inherited from class java.io.SequenceInputStream
available, close, read, read
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ARGVInputStream

public ARGVInputStream(String... args)
Create an ARGVInputStream.

Parameters:
args - Command line arguments or some other String array containing 0 or more file names.

JAPI
Yet another Java API
API Documentation

© 2005-2006 Christian Hujer. All rights reserved. See copyright