Java Code Examples for java.io.PipedWriter#write()
The following examples show how to use
java.io.PipedWriter#write() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Piped.java From javacore with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
public static void main(String[] args) throws Exception { PipedWriter out = new PipedWriter(); PipedReader in = new PipedReader(); // 将输出流和输入流进行连接,否则在使用时会抛出IOException out.connect(in); Thread printThread = new Thread(new Print(in), "PrintThread"); printThread.start(); int receive = 0; try { while ((receive = System.in.read()) != -1) { out.write(receive); } } finally { out.close(); } }
Example 2
Source File: OldPipedWriterTest.java From j2objc with Apache License 2.0 | 6 votes |
public void test_writeI() throws Exception { // Test for method void java.io.PipedWriter.write(int) pw = new PipedWriter(); try { pw.write(42); fail("Test 1: IOException expected."); } catch (IOException e) { // Expected. } readerThread = new Thread(reader = new PReader(pw), "writeI"); readerThread.start(); pw.write(1); pw.write(2); pw.write(3); pw.close(); reader.read(3); assertTrue("Test 2: The charaacters read do not match the characters written: " + (int) reader.buf[0] + " " + (int) reader.buf[1] + " " + (int) reader.buf[2], reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3); }
Example 3
Source File: InterruptedStreamTest.java From j2objc with Apache License 2.0 | 5 votes |
private void testInterruptWriter(final PipedWriter writer) throws Exception { Thread thread = interruptMeLater(); try { // this will block when the receiving buffer fills up while (true) { writer.write(new char[BUFFER_SIZE]); } } catch (InterruptedIOException expected) { } finally { confirmInterrupted(thread); } }
Example 4
Source File: OldPipedWriterTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_flush() throws Exception { // Test for method void java.io.PipedWriter.flush() pw = new PipedWriter(); readerThread = new Thread(reader = new PReader(pw), "flush"); readerThread.start(); pw.write(testBuf); pw.flush(); assertEquals("Test 1: Flush failed. ", testString, reader.read(testLength)); }