java类java.io.PipedReader的实例源码

ScriptEngineService.java 文件源码 项目:https-github.com-hyb1996-NoRootScriptDroid 阅读 22 收藏 0 点赞 0 评论 0
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();
    }
}
ScriptEngineService.java 文件源码 项目:Auto.js 阅读 20 收藏 0 点赞 0 评论 0
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();
    }
}
ProlMemoryPipe.java 文件源码 项目:jprol 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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);
}
PipedWriterTest.java 文件源码 项目:In-the-Box-Fork 阅读 21 收藏 0 点赞 0 评论 0
/**
 * @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());
    }
}
PipedReaderTest.java 文件源码 项目:In-the-Box-Fork 阅读 21 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedReaderTest.java 文件源码 项目:In-the-Box-Fork 阅读 19 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedWriterTest.java 文件源码 项目:cn1 阅读 19 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedWriterTest.java 文件源码 项目:cn1 阅读 19 收藏 0 点赞 0 评论 0
/**
 * @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));
}
WriterTesterTest.java 文件源码 项目:cn1 阅读 28 收藏 0 点赞 0 评论 0
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;
}
PipedReaderTest.java 文件源码 项目:cn1 阅读 19 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedReaderTest.java 文件源码 项目:cn1 阅读 20 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedWriterTest.java 文件源码 项目:freeVM 阅读 18 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedWriterTest.java 文件源码 项目:freeVM 阅读 19 收藏 0 点赞 0 评论 0
/**
 * @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));
}
PipedReaderTest.java 文件源码 项目:freeVM 阅读 25 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedReaderTest.java 文件源码 项目:freeVM 阅读 21 收藏 0 点赞 0 评论 0
/**
 * @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
       }
   }
PipedWriterTest.java 文件源码 项目:freeVM 阅读 23 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedWriterTest.java 文件源码 项目:freeVM 阅读 25 收藏 0 点赞 0 评论 0
/**
 * @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));
}
WriterTesterTest.java 文件源码 项目:freeVM 阅读 23 收藏 0 点赞 0 评论 0
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;
}
PipedReaderTest.java 文件源码 项目:freeVM 阅读 21 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
PipedReaderTest.java 文件源码 项目:freeVM 阅读 17 收藏 0 点赞 0 评论 0
/**
 * @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
    }
}
CSVParserTest.java 文件源码 项目:commons-csv 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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());
    }
}
ReaderBulkReadContract.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
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);
    }
}
ReaderBulkReadContract.java 文件源码 项目:openjdk9 阅读 22 收藏 0 点赞 0 评论 0
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);
    }
}
TankAnalyzerTest.java 文件源码 项目:Tank 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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);
}
InterruptedStreamTest.java 文件源码 项目:j2objc 阅读 20 收藏 0 点赞 0 评论 0
private void testInterruptReader(final PipedReader reader) throws Exception {
    Thread thread = interruptMeLater();
    try {
        reader.read();
        fail();
    } catch (InterruptedIOException expected) {
    } finally {
        confirmInterrupted(thread);
    }
}
OldPipedWriterTest.java 文件源码 项目:j2objc 阅读 22 收藏 0 点赞 0 评论 0
public PReader(PipedWriter pw) {
    try {
        pr = new PipedReader(pw);
    } catch (IOException e) {
        System.out.println("Exception setting up reader: "
                + e.toString());
    }
}
OldPipedWriterTest.java 文件源码 项目:j2objc 阅读 22 收藏 0 点赞 0 评论 0
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());
    }
}
ResultWriterTest.java 文件源码 项目:Java-Algorithms 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void testCheckWrittenResult()
        throws Exception {
    final PipedWriter writer = new PipedWriter();
    final BufferedReader reader = new BufferedReader(new PipedReader(writer));
    resultWriter.writeTo(writer);
    final String resultString = reader.readLine();
    assertThat("Case #1: 2", is(equalTo(resultString)));
}
PipedWriterTest.java 文件源码 项目:In-the-Box-Fork 阅读 21 收藏 0 点赞 0 评论 0
public PReader(PipedWriter pw) {
    try {
        pr = new PipedReader(pw);
    } catch (IOException e) {
        System.out.println("Exception setting up reader: "
                + e.toString());
    }
}
PipedReaderTest.java 文件源码 项目:In-the-Box-Fork 阅读 18 收藏 0 点赞 0 评论 0
public PWriter(PipedReader reader) {
    try {
        pw = new PipedWriter(reader);
    } catch (Exception e) {
        System.out.println("Couldn't create writer");
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号