本文整理匯總了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
}
}