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


Java PipedWriter.write方法代碼示例

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


在下文中一共展示了PipedWriter.write方法的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_flush

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#flush()
 */
@TestTargetNew(
    level = TestLevel.SUFFICIENT,
    notes = "No IOException checking because it is never thrown in the source code.",
    method = "flush",
    args = {}
)
public void test_flush() throws Exception {
    // Test for method void java.io.PipedWriter.flush()
    pw = new PipedWriter();
    readerThread = new Thread(reader = new PReader(pw), "flush");
    readerThread.start();
    pw.write(testBuf);
    pw.flush();
    assertEquals("Test 1: Flush failed. ", testString,
            reader.read(testLength));
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:20,代碼來源:PipedWriterTest.java

示例3: 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

示例4: 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

示例5: 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

示例6: testInterruptWriter

import java.io.PipedWriter; //導入方法依賴的package包/類
private void testInterruptWriter(final PipedWriter writer) throws Exception {
    Thread thread = interruptMeLater();
    try {
        // this will block when the receiving buffer fills up
        while (true) {
            writer.write(new char[BUFFER_SIZE]);
        }
    } catch (InterruptedIOException expected) {
    } finally {
        confirmInterrupted(thread);
    }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:13,代碼來源:InterruptedStreamTest.java

示例7: test_flush

import java.io.PipedWriter; //導入方法依賴的package包/類
public void test_flush() throws Exception {
    // Test for method void java.io.PipedWriter.flush()
    pw = new PipedWriter();
    readerThread = new Thread(reader = new PReader(pw), "flush");
    readerThread.start();
    pw.write(testBuf);
    pw.flush();
    assertEquals("Test 1: Flush failed. ", testString,
            reader.read(testLength));
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:11,代碼來源:OldPipedWriterTest.java

示例8: 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

示例9: 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

示例10: test_flush

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#flush()
 */
public void test_flush() throws Exception {
    // Test for method void java.io.PipedWriter.flush()
    char[] buf = new char[10];
    "HelloWorld".getChars(0, 10, buf, 0);
    pw = new PipedWriter();
    rdrThread = new Thread(reader = new PReader(pw), "flush");
    rdrThread.start();
    pw.write(buf);
    pw.flush();
    rdrThread.join(700);
    assertEquals("Failed to flush chars", "HelloWorld", new String(
            reader.buf));
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:17,代碼來源: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: PipedReader

import java.io.PipedWriter; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedWriter#write(char[], int, int) Regression for
 *        HARMONY-387
 */
public void test_write$CII_2() throws IOException {
    PipedReader pr = new PipedReader();
    PipedWriter obj = null;
    try {
        obj = new java.io.PipedWriter(pr);
        obj.write(new char[0], (int) 0, (int) -1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException t) {
        assertEquals(
                "IndexOutOfBoundsException rather than a subclass expected",
                IndexOutOfBoundsException.class, t.getClass());
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:18,代碼來源:PipedWriterTest.java


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