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


Java PipedReader類代碼示例

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


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

示例1: getScriptTrace

import java.io.PipedReader; //導入依賴的package包/類
private static String getScriptTrace(Exception e) {
    try {
        PipedReader reader = new PipedReader(8192);
        PrintWriter writer = new PrintWriter(new PipedWriter(reader));
        e.printStackTrace(writer);
        writer.close();
        BufferedReader bufferedReader = new BufferedReader(reader);
        String line;
        StringBuilder scriptTrace = new StringBuilder(e.getMessage());
        while ((line = bufferedReader.readLine()) != null) {
            if (line.trim().startsWith("at script"))
                scriptTrace.append("\n").append(line);
        }
        return scriptTrace.toString();
    } catch (IOException e1) {
        e1.printStackTrace();
        return e.getMessage();
    }
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:20,代碼來源:ScriptEngineService.java

示例2: getScriptTrace

import java.io.PipedReader; //導入依賴的package包/類
private static String getScriptTrace(Exception e) {
    try {
        PipedReader reader = new PipedReader(8192);
        PrintWriter writer = new PrintWriter(new PipedWriter(reader));
        e.printStackTrace(writer);
        writer.close();
        BufferedReader bufferedReader = new BufferedReader(reader);
        String line;
        StringBuilder scriptTrace = new StringBuilder(TextUtils.toEmptyIfNull(e.getMessage()));
        while ((line = bufferedReader.readLine()) != null) {
            if (line.trim().startsWith("at script"))
                scriptTrace.append("\n").append(line);
        }
        return scriptTrace.toString();
    } catch (IOException e1) {
        e1.printStackTrace();
        return e.getMessage();
    }
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:20,代碼來源:ScriptEngineService.java

示例3: ProlMemoryPipe

import java.io.PipedReader; //導入依賴的package包/類
/**
 * The constructor
 *
 * @param resourceId the resource identifier, must not be null
 * @param context    the owner context for the pipe, must not be null
 * @throws IOException it will be thrown if there will be any transport errors
 */
public ProlMemoryPipe(final String resourceId, final ProlContext context) throws IOException {
    if (resourceId == null) {
        throw new IllegalArgumentException("Resource identifier must not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("Context must not be null");
    }

    this.resourceId = resourceId;
    this.context = context;

    final PipedWriter pipeWriter = new PipedWriter();
    final PipedReader pipeReader = new PipedReader(pipeWriter);

    reader = new ProlTextInputStream(pipeReader, context);
    writer = new ProlTextOutputStream(pipeWriter, context, false);
}
 
開發者ID:raydac,項目名稱:jprol,代碼行數:25,代碼來源:ProlMemoryPipe.java

示例4: test_close

import java.io.PipedReader; //導入依賴的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

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

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

示例7: test_close

import java.io.PipedReader; //導入依賴的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

示例8: test_connectLjava_io_PipedReader

import java.io.PipedReader; //導入依賴的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

示例9: create

import java.io.PipedReader; //導入依賴的package包/類
public Writer create() throws IOException {
    final PipedReader in = new PipedReader();
    PipedWriter out = new PipedWriter(in);

    executor = Executors.newSingleThreadExecutor();
    future = executor.submit(new Callable<char[]>() {
        final CharArrayWriter chars = new CharArrayWriter();
        public char[] call() throws Exception {
            char[] buffer = new char[256];
            int count;
            while ((count = in.read(buffer)) != -1) {
                chars.write(buffer, 0, count);
            }
            return chars.toCharArray();
        }
    });

    return out;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:20,代碼來源:WriterTesterTest.java

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

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

示例12: testGetOneLineOneParser

import java.io.PipedReader; //導入依賴的package包/類
/**
 * Tests reusing a parser to process new string records one at a time as they are being discovered. See [CSV-110].
 *
 * @throws IOException
 */
@Test
public void testGetOneLineOneParser() throws IOException {
    final CSVFormat format = CSVFormat.DEFAULT;
    try (final PipedWriter writer = new PipedWriter();
            final CSVParser parser = new CSVParser(new PipedReader(writer), format)) {
        writer.append(CSV_INPUT_1);
        writer.append(format.getRecordSeparator());
        final CSVRecord record1 = parser.nextRecord();
        assertArrayEquals(RESULT[0], record1.values());
        writer.append(CSV_INPUT_2);
        writer.append(format.getRecordSeparator());
        final CSVRecord record2 = parser.nextRecord();
        assertArrayEquals(RESULT[1], record2.values());
    }
}
 
開發者ID:apache,項目名稱:commons-csv,代碼行數:21,代碼來源:CSVParserTest.java

示例13: newPipedReader

import java.io.PipedReader; //導入依賴的package包/類
private static PipedReader newPipedReader(String contents) {
    try (PipedWriter w = new PipedWriter()) {
        PipedReader r = new PipedReader(w);
        w.write(contents);
        return r;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:ReaderBulkReadContract.java

示例14: testCreateComponents_1

import java.io.PipedReader; //導入依賴的package包/類
/**
 * Run the org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents createComponents(String,Reader)
 * method test.
 * 
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/10/14 10:27 AM
 */
@Test
public void testCreateComponents_1()
        throws Exception {
    TankAnalyzer fixture = new TankAnalyzer(Version.LUCENE_20);
    String fieldName = "";
    Reader reader = new PipedReader();

    org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents result = fixture.createComponents(
            fieldName, reader);

    assertNotNull(result);
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:21,代碼來源:TankAnalyzerTest.java

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


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