/** @tests java.io.PipedReader#connect(java.io.PipedWriter) */ public void test_connectLjava_io_PipedWriter() throws Exception { char[] c = null; preader = new PipedReader(); t = new Thread(pwriter = new PWriter(), ""); preader.connect(pwriter.pw); t.start(); Thread.sleep(500); // Allow writer to start c = new char[11]; preader.read(c, 0, 11); assertEquals("Read incorrect chars", "Hello World", new String(c)); try { preader.connect(pwriter.pw); fail("Failed to throw exception connecting to pre-connected reader"); } catch (IOException e) { // Expected } }
/** Set up the pager's console and command pipe. */ private void setup() throws NameNotFoundException, IOException { ShellManager sm = InitialNaming.lookup(ShellManager.NAME); manager = (TextScreenConsoleManager) sm.getCurrentShell().getConsole().getManager(); console = manager.createConsole( "page", (ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.STACKED | ConsoleManager.CreateOptions.NO_LINE_EDITTING | ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR)); manager.focus(console); pageHeight = console.getDeviceHeight() - 1; pageWidth = console.getDeviceWidth(); pageSize = pageHeight * pageWidth; tabSize = console.getTabSize(); pw = new PipedWriter(); pr = new PipedReader(); pr.connect(pw); console.addKeyboardListener(this); }
/** * Constructs a new {@code PipedReader} connected to the {@link PipedWriter} {@code out}. Any data * written to the writer can be read from the this reader. * * @param out the {@code PipedWriter} to connect to. * @throws IOException if {@code out} is already connected. */ public PipedReader(PipedWriter out) throws IOException { this(); connect(out); }
/** * Constructs a new PipedReader connected to the PipedWriter <code>out</code> and the buffer size * is specified. Any data written to the writer can be read from the this reader. * * @param out the PipedWriter to connect to. * @param pipeSize the size of the buffer. * @throws IOException if IO errors occur * @throws IllegalArgumentException if pipeSize is less than or equal to zero. * @since 1.6 */ public PipedReader(PipedWriter out, int pipeSize) throws IOException { this(pipeSize); connect(out); }