Also available as SysInAvailable.java

/**
 * Title: SysInAvailable
 * Description: System.in as an InputStream
 *   echo everything that is available
 *
 * If you run this with input coming from the keyboard,
 * available() will initially return a 0, and the program
 * will read nothing.
 *
 * try this: echo "hello" | java SysInAvailable
 * or this: cat SysInAvailable.java | java SysInAvailable
 *
 * @author hollingd@cs.rpi.edu
 */
import java.io.*;

public class SysInAvailable{

    public static void main(String[] args){

        InputStream stdin = System.in;
        try {
            byte []b = new byte[stdin.available()];
            int len = stdin.read(b);        
            for (int i=0;i<len;i++) 
                System.out.write(b[i]);
            System.out.flush();
        } catch ( IOException e) {
            e.printStackTrace();
        }
    }
}