當前位置: 首頁>>代碼示例>>Java>>正文


Java PipedWriter.close方法代碼示例

本文整理匯總了Java中java.io.PipedWriter.close方法的典型用法代碼示例。如果您正苦於以下問題:Java PipedWriter.close方法的具體用法?Java PipedWriter.close怎麽用?Java PipedWriter.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.PipedWriter的用法示例。


在下文中一共展示了PipedWriter.close方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_writeI

import java.io.PipedWriter; //導入方法依賴的package包/類
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);
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:24,代碼來源:OldPipedWriterTest.java

示例2: test_Constructor

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#PipedWriter()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "PipedWriter",
    args = {}
)
public void test_Constructor() {
    pw = new PipedWriter();
    assertNotNull(pw);
    try {
        pw.close();
    } catch (IOException e) {
        fail("Unexpeceted IOException.");
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:19,代碼來源:PipedWriterTest.java

示例3: test_close

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#close()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "close",
    args = {}
)
public void test_close() throws Exception {
    PipedReader rd = new PipedReader();
    pw = new PipedWriter(rd);
    reader = new PReader(rd);
    try {
        pw.close();
    } catch (IOException e) {
        fail("Test 1: Unexpected IOException: " + e.getMessage());
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:20,代碼來源:PipedWriterTest.java

示例4: test_close

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#close()
 */
public void test_close() throws Exception {
    // Test for method void java.io.PipedWriter.close()
    char[] buf = new char[10];
    "HelloWorld".getChars(0, 10, buf, 0);
    PipedReader rd = new PipedReader();
    pw = new PipedWriter(rd);
    reader = new PReader(rd);
    pw.close();
    try {
        pw.write(buf);
        fail("Should have thrown exception when attempting to write to closed writer.");
    } catch (Exception e) {
        // correct
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:19,代碼來源:PipedWriterTest.java

示例5: 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));
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:19,代碼來源:PipedWriterTest.java

示例6: test_writeI

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#write(int)
 */
public void test_writeI() throws Exception {
    // Test for method void java.io.PipedWriter.write(int)

    pw = new PipedWriter();
    rdrThread = new Thread(reader = new PReader(pw), "writeI");
    rdrThread.start();
    pw.write(1);
    pw.write(2);
    pw.write(3);
    pw.close();
    rdrThread.join(1000);
    assertTrue("Failed to write correct chars: " + (int) reader.buf[0]
            + " " + (int) reader.buf[1] + " " + (int) reader.buf[2],
            reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3);
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:19,代碼來源:PipedWriterTest.java

示例7: test_Constructor

import java.io.PipedWriter; //導入方法依賴的package包/類
public void test_Constructor() {
    pw = new PipedWriter();
    assertNotNull(pw);
    try {
        pw.close();
    } catch (IOException e) {
        fail("Unexpeceted IOException.");
    }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:10,代碼來源:OldPipedWriterTest.java

示例8: test_close

import java.io.PipedWriter; //導入方法依賴的package包/類
public void test_close() throws Exception {
    PipedReader rd = new PipedReader();
    pw = new PipedWriter(rd);
    reader = new PReader(rd);
    try {
        pw.close();
    } catch (IOException e) {
        fail("Test 1: Unexpected IOException: " + e.getMessage());
    }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:11,代碼來源:OldPipedWriterTest.java

示例9: test_writeI

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#write(int)
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "write",
    args = {int.class}
)
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);
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:33,代碼來源:PipedWriterTest.java

示例10: test_ConstructorLjava_io_PipedReader

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#PipedWriter(java.io.PipedReader)
 */
public void test_ConstructorLjava_io_PipedReader() throws Exception {
    // Test for method java.io.PipedWriter(java.io.PipedReader)
    char[] buf = new char[10];
    "HelloWorld".getChars(0, 10, buf, 0);
    PipedReader rd = new PipedReader();
    pw = new PipedWriter(rd);
    rdrThread = new Thread(reader = new PReader(rd), "Constructor(Reader)");
    rdrThread.start();
    pw.write(buf);
    pw.close();
    rdrThread.join(500);
    assertEquals("Failed to construct writer", "HelloWorld", new String(
            reader.buf));
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:18,代碼來源:PipedWriterTest.java

示例11: PipedWriter

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#write(char[], int, int)
 */
public void test_write$CII() throws Exception {
    // Test for method void java.io.PipedWriter.write(char [], int, int)
    char[] buf = new char[10];
    "HelloWorld".getChars(0, 10, buf, 0);
    pw = new PipedWriter();
    rdrThread = new Thread(reader = new PReader(pw), "writeCII");
    rdrThread.start();
    pw.write(buf, 0, 10);
    pw.close();
    rdrThread.join(1000);
    assertEquals("Failed to write correct chars", "HelloWorld", new String(
            reader.buf));
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:17,代碼來源:PipedWriterTest.java

示例12: 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();
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:35,代碼來源:XsltStylesheet.java


注:本文中的java.io.PipedWriter.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。