本文整理汇总了Java中java.io.PipedReader.connect方法的典型用法代码示例。如果您正苦于以下问题:Java PipedReader.connect方法的具体用法?Java PipedReader.connect怎么用?Java PipedReader.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.PipedReader
的用法示例。
在下文中一共展示了PipedReader.connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_connectLjava_io_PipedWriter
import java.io.PipedReader; //导入方法依赖的package包/类
/**
* @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
}
}
示例2: test_connectLjava_io_PipedWriter
import java.io.PipedReader; //导入方法依赖的package包/类
/**
* @tests java.io.PipedReader#connect(java.io.PipedWriter)
*/
public void test_connectLjava_io_PipedWriter() throws Exception {
// Test for method void java.io.PipedReader.connect(java.io.PipedWriter)
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 (Exception e) {
// Correct
}
}