< prev index next >

src/jdk.jshell/share/classes/jdk/jshell/execution/PipeInputStream.java

Print this page
rev 3613 : imported patch 8131023

*** 22,32 **** --- 22,34 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package jdk.jshell.execution; + import java.io.IOException; import java.io.InputStream; + import java.io.OutputStream; /** * * @author Jan Lahoda */
*** 37,47 **** private int start; private int end; private boolean closed; @Override ! public synchronized int read() { while (start == end) { if (closed) { return -1; } try { --- 39,52 ---- private int start; private int end; private boolean closed; @Override ! public synchronized int read() throws IOException { ! if (start == end) { ! inputNeeded(); ! } while (start == end) { if (closed) { return -1; } try {
*** 55,65 **** } finally { start = (start + 1) % buffer.length; } } ! public synchronized void write(int b) { if (closed) { throw new IllegalStateException("Already closed."); } int newEnd = (end + 1) % buffer.length; if (newEnd == start) { --- 60,72 ---- } finally { start = (start + 1) % buffer.length; } } ! protected void inputNeeded() throws IOException {} ! ! private synchronized void write(int b) { if (closed) { throw new IllegalStateException("Already closed."); } int newEnd = (end + 1) % buffer.length; if (newEnd == start) {
*** 83,88 **** --- 90,113 ---- public synchronized void close() { closed = true; notifyAll(); } + public OutputStream createOutput() { + return new OutputStream() { + @Override public void write(int b) throws IOException { + PipeInputStream.this.write(b); + } + @Override + public void write(byte[] b, int off, int len) throws IOException { + for (int i = 0 ; i < len ; i++) { + write(Byte.toUnsignedInt(b[off + i])); + } + } + @Override + public void close() throws IOException { + PipeInputStream.this.close(); + } + }; + } + }
< prev index next >