本文整理匯總了Java中java.io.PipedWriter.connect方法的典型用法代碼示例。如果您正苦於以下問題:Java PipedWriter.connect方法的具體用法?Java PipedWriter.connect怎麽用?Java PipedWriter.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.PipedWriter
的用法示例。
在下文中一共展示了PipedWriter.connect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_connectLjava_io_PipedReader
import java.io.PipedWriter; //導入方法依賴的package包/類
/**
* @tests java.io.PipedWriter#connect(java.io.PipedReader)
*/
public void test_connectLjava_io_PipedReader() throws Exception {
// Test for method void java.io.PipedWriter.connect(java.io.PipedReader)
char[] buf = new char[10];
"HelloWorld".getChars(0, 10, buf, 0);
PipedReader rd = new PipedReader();
pw = new PipedWriter();
pw.connect(rd);
rdrThread = new Thread(reader = new PReader(rd), "connect");
rdrThread.start();
pw.write(buf);
pw.close();
rdrThread.join(500);
assertEquals("Failed to write correct chars", "HelloWorld", new String(
reader.buf));
}
示例2: retryXsltTransformation
import java.io.PipedWriter; //導入方法依賴的package包/類
private String retryXsltTransformation(ThreadContext context,
IRubyObject[] args,
DOMSource domSource,
NokogiriXsltErrorListener elistener)
throws TransformerException, IOException {
Templates templates = getTemplatesFromStreamSource();
Transformer transf = templates.newTransformer();
transf.setErrorListener(elistener);
if (args.length > 1) {
addParametersToTransformer(context, transf, args[1]);
}
PipedWriter pwriter = new PipedWriter();
PipedReader preader = new PipedReader();
pwriter.connect(preader);
StreamResult result = new StreamResult(pwriter);
transf.transform(domSource, result);
char[] cbuf = new char[1024];
int len = preader.read(cbuf, 0, 1024);
StringBuilder builder = new StringBuilder();
builder.append(CharBuffer.wrap(cbuf, 0, len));
htmlish = isHtml(builder.toString()); // judge from the first chunk
while (len == 1024) {
len = preader.read(cbuf, 0, 1024);
if (len > 0) {
builder.append(CharBuffer.wrap(cbuf, 0, len));
}
}
preader.close();
pwriter.close();
return builder.toString();
}