title: Write java unix commands with libraries
body: <p><strong>To be clear: This question is not about how to parse arguments to the program like commons CLI/JCommando etc. does.</strong></p>
  
  <p>I would like to write Unix commands using Java. Although I don't want to write most of the stuff myself, I intend to use libraries and looking for your help to do so.</p>
  
  <p>I found commons cli for parse arguments, like getopt. <strong>However I am looking for a last piece of library that works like Perl's diamond operator or Python's fileinput-library.</strong></p>
  
  <p>As unix commands (or GNU commands as I come from Linux) works is that after any flags have been parsed any arguments left are considered files. The command then loops through these files line by line, file by file. A dubble dash (e.g. git checkout -- myfile.txt) is there to separate  filenames from arguments. If no arguments are left after parsing all arguments the program should read from standard in instead.</p>
  
  <p>This is what Perl's diamond operator does as well as Python's fileinput library, on very very few lines:</p>
  
  <p>Perl</p>
  
  <pre class="lang-pl prettyprint-override"><code>@ARGV = ("diamond.pl", "stdin.pl");
  while (&lt;&gt;) {
      print();
  }
  </code></pre>
  
  <p>Python</p>
  
  <pre class="lang-py prettyprint-override"><code>import fileinput
  for line in fileinput.input():
      process(line)
  </code></pre>
  
  <p>Is there a library in Java that does what these do as simple as they do it (a library that basically have the same API as <a href="https://docs.python.org/2/library/fileinput.html" rel="nofollow">https://docs.python.org/2/library/fileinput.html</a>)? I don't want to write the stuff myself (look for arguments, if not loop through stdin otherwise load each file, preferably lazy, feed each line to the command etc)...I just want the business end, the loop like:</p>
  
  <p>My idea</p>
  
  <pre class="lang-java prettyprint-override"><code>LineIterator li = new MagicTextLineFeeder(remainingAfterCommonsCliParsing);
  for (String line : li.nextRow()) {
      System.out.println(line);
  }
  </code></pre>
  
  <p>EDIT: Made it clear that I don't looking for another argument parsing library. </p>