本文整理匯總了Java中java.io.PipedReader.close方法的典型用法代碼示例。如果您正苦於以下問題:Java PipedReader.close方法的具體用法?Java PipedReader.close怎麽用?Java PipedReader.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.PipedReader
的用法示例。
在下文中一共展示了PipedReader.close方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: PipedReader
import java.io.PipedReader; //導入方法依賴的package包/類
/**
* @tests java.io.PipedReader#read(char[], int, int)
*/
public void test_read$CII() throws Exception {
char[] c = null;
preader = new PipedReader();
t = new Thread(new PWriter(preader), "");
t.start();
Thread.sleep(500); // Allow writer to start
c = new char[11];
int n = 0;
int x = n;
while (x < 11) {
n = preader.read(c, x, 11 - x);
x = x + n;
}
assertEquals("Read incorrect chars", "Hello World", new String(c));
try {
preader.close();
preader.read(c, 8, 7);
fail("Failed to throw exception reading from closed reader");
} catch (IOException e) {
// Expected
}
}
示例2: PipedReader
import java.io.PipedReader; //導入方法依賴的package包/類
/**
* @tests java.io.PipedReader#read(char[], int, int)
*/
public void test_read$CII() throws Exception {
// Test for method int java.io.PipedReader.read(char [], int, int)
char[] c = null;
preader = new PipedReader();
t = new Thread(new PWriter(preader), "");
t.start();
Thread.sleep(500); // Allow writer to start
c = new char[11];
int n = 0;
int x = n;
while (x < 11) {
n = preader.read(c, x, 11 - x);
x = x + n;
}
assertEquals("Read incorrect chars", "Hello World", new String(c));
try {
preader.close();
preader.read(c, 8, 7);
fail("Failed to throw exception reading from closed reader");
} catch (Exception e) {
// Correct
}
}
示例3: test_close
import java.io.PipedReader; //導入方法依賴的package包/類
/**
* @tests java.io.PipedReader#close()
*/
public void test_close() throws Exception {
char[] c = null;
preader = new PipedReader();
t = new Thread(new PWriter(preader), "");
t.start();
Thread.sleep(500); // Allow writer to start
c = new char[11];
preader.read(c, 0, 11);
preader.close();
assertEquals("Read incorrect chars", "Hello World", new String(c));
}
示例4: retryXsltTransformation
import java.io.PipedReader; //導入方法依賴的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();
}
示例5: test_close
import java.io.PipedReader; //導入方法依賴的package包/類
/**
* @tests java.io.PipedReader#close()
*/
public void test_close() throws Exception {
// Test for method void java.io.PipedReader.close()
char[] c = null;
preader = new PipedReader();
t = new Thread(new PWriter(preader), "");
t.start();
Thread.sleep(500); // Allow writer to start
c = new char[11];
preader.read(c, 0, 11);
preader.close();
assertEquals("Read incorrect chars", "Hello World", new String(c));
}
示例6: testGetInfo
import java.io.PipedReader; //導入方法依賴的package包/類
/**
* Test sysinfo.getInfo()
*
* Currently only tests getInfo() by comparing the first line with the
* expected first line in English. Because so much of sysinfo changes from
* machine-to-machine, writing a better test may be difficult.
*
* Test spawns a separate thread in which to call sysinfo and feed the
* PipedWriter. Using PipedWriter and PipedReader from the same thread
* can cause a deadlock.
*/
public void testGetInfo() throws IOException {
sysinfo_api_helper sah = new sysinfo_api_helper();
sah.start();
PipedReader pipeR = new PipedReader(sah.getPipedWriter());
BufferedReader br = new BufferedReader(pipeR);
assertEquals("------------------ Java Information ------------------",
br.readLine());
br.close();
pipeR.close();
}