Code example for PipedInputStream

Methods: read

0
            return reader;
        } 
 
        public PReader(PipedOutputStream out) {
            try { 
                reader = new PipedInputStream(out);
            } catch (Exception e) {
                System.out.println("Exception setting up reader: "
                        + e.toString());
            } 
        } 
 
        public int available() { 
            try { 
                return reader.available();
            } catch (Exception e) {
                return -1; 
            } 
        } 
 
        public void run() { 
            try { 
                while (true) { 
                    Thread.sleep(1000);
                    Thread.yield();
                } 
            } catch (InterruptedException e) {
            } 
        } 
 
        public String read(int nbytes) {
            byte[] buf = new byte[nbytes];
            try { 
                reader.read(buf, 0, nbytes);
                return new String(buf);
            } catch (IOException e) {
                System.out.println("Exception reading ("
                        + Thread.currentThread().getName() + "): "
                        + e.toString());