当前位置: 首页>>代码示例>>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;未经允许,请勿转载。