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


Java PipedReader.read方法代碼示例

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


在下文中一共展示了PipedReader.read方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:23,代碼來源:PipedReaderTest.java

示例2: 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
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:26,代碼來源:PipedReaderTest.java

示例3: 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
    }
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:24,代碼來源:PipedReaderTest.java

示例4: 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
       }
   }
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:27,代碼來源:PipedReaderTest.java

示例5: testInterruptReader

import java.io.PipedReader; //導入方法依賴的package包/類
private void testInterruptReader(final PipedReader reader) throws Exception {
    Thread thread = interruptMeLater();
    try {
        reader.read();
        fail();
    } catch (InterruptedIOException expected) {
    } finally {
        confirmInterrupted(thread);
    }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:11,代碼來源:InterruptedStreamTest.java

示例6: 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));
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:15,代碼來源:PipedReaderTest.java

示例7: test_read

import java.io.PipedReader; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedReader#read()
 */
public void test_read() 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];
    for (int i = 0; i < c.length; i++) {
        c[i] = (char) preader.read();
    }
    assertEquals("Read incorrect chars", "Hello World", new String(c));
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:16,代碼來源:PipedReaderTest.java

示例8: test_ready

import java.io.PipedReader; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedReader#ready()
 */
public void test_ready() throws Exception {
    char[] c = null;
    preader = new PipedReader();
    t = new Thread(new PWriter(preader), "");
    t.start();
    Thread.sleep(500); // Allow writer to start
    assertTrue("Reader should be ready", preader.ready());
    c = new char[11];
    for (int i = 0; i < c.length; i++)
        c[i] = (char) preader.read();
    assertFalse("Reader should not be ready after reading all chars",
            preader.ready());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:17,代碼來源:PipedReaderTest.java

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

示例10: 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));
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:16,代碼來源:PipedReaderTest.java

示例11: test_read

import java.io.PipedReader; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedReader#read()
 */
public void test_read() throws Exception {
       // Test for method int java.io.PipedReader.read()
       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];
       for (int i = 0; i < c.length; i++) {
           c[i] = (char) preader.read();
       }
       assertEquals("Read incorrect chars", "Hello World", new String(c));
   }
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:17,代碼來源:PipedReaderTest.java

示例12: test_ready

import java.io.PipedReader; //導入方法依賴的package包/類
/**
 * @tests java.io.PipedReader#ready()
 */
public void test_ready() throws Exception {
       // Test for method boolean java.io.PipedReader.ready()
       char[] c = null;
       preader = new PipedReader();
       t = new Thread(new PWriter(preader), "");
       t.start();
       Thread.sleep(500); // Allow writer to start
       assertTrue("Reader should be ready", preader.ready());
       c = new char[11];
       for (int i = 0; i < c.length; i++)
           c[i] = (char) preader.read();
       assertFalse("Reader should not be ready after reading all chars",
               preader.ready());
   }
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:18,代碼來源:PipedReaderTest.java


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