net.sf.japi.io
Class ARGVInputStream
java.lang.Object
java.io.InputStream
java.io.SequenceInputStream
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()
.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ARGVInputStream
public ARGVInputStream(String... args)
- Create an ARGVInputStream.
- Parameters:
args
- Command line arguments or some other String array containing 0 or more file names.
© 2005-2006 Christian Hujer. All rights reserved. See
copyright