Java 类java.io.PipedWriter 实例源码

项目:https-github.com-hyb1996-NoRootScriptDroid    文件:ScriptEngineService.java   
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();
    }
}
项目:Auto.js    文件:ScriptEngineService.java   
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();
    }
}
项目:jprol    文件:ProlMemoryPipe.java   
/**
 * 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);
}
项目:j2objc    文件:OldPipedWriterTest.java   
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);
}
项目:In-the-Box-Fork    文件:PipedWriterTest.java   
/**
 * @tests java.io.PipedWriter#PipedWriter()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "PipedWriter",
    args = {}
)
public void test_Constructor() {
    pw = new PipedWriter();
    assertNotNull(pw);
    try {
        pw.close();
    } catch (IOException e) {
        fail("Unexpeceted IOException.");
    }
}
项目:In-the-Box-Fork    文件:PipedWriterTest.java   
/**
 * @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());
    }
}
项目:In-the-Box-Fork    文件:PipedWriterTest.java   
/**
 * @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));
}
项目:cn1    文件:PipedWriterTest.java   
/**
 * @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
    }
}
项目:cn1    文件:PipedWriterTest.java   
/**
 * @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));
}
项目:cn1    文件:PipedWriterTest.java   
/**
 * @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);
}
项目:cn1    文件:WriterTesterTest.java   
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;
}
项目:freeVM    文件:PipedWriterTest.java   
/**
 * @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
    }
}
项目:freeVM    文件:PipedWriterTest.java   
/**
 * @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));
}
项目:freeVM    文件:PipedWriterTest.java   
/**
 * @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);
}
项目:freeVM    文件:PipedWriterTest.java   
/**
 * @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
    }
}
项目:freeVM    文件:PipedWriterTest.java   
/**
 * @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));
}
项目:freeVM    文件:PipedWriterTest.java   
/**
 * @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);
}
项目:freeVM    文件:WriterTesterTest.java   
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;
}
项目:commons-csv    文件:CSVParserTest.java   
/**
 * 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());
    }
}
项目:openjdk-jdk10    文件:ReaderBulkReadContract.java   
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);
    }
}
项目:openjdk9    文件:ReaderBulkReadContract.java   
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);
    }
}
项目:j2objc    文件:InterruptedStreamTest.java   
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);
    }
}
项目:j2objc    文件:OldPipedWriterTest.java   
public PReader(PipedWriter pw) {
    try {
        pr = new PipedReader(pw);
    } catch (IOException e) {
        System.out.println("Exception setting up reader: "
                + e.toString());
    }
}
项目:j2objc    文件:OldPipedWriterTest.java   
public void test_Constructor() {
    pw = new PipedWriter();
    assertNotNull(pw);
    try {
        pw.close();
    } catch (IOException e) {
        fail("Unexpeceted IOException.");
    }
}
项目:j2objc    文件:OldPipedWriterTest.java   
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());
    }
}
项目:j2objc    文件:OldPipedWriterTest.java   
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));
}
项目:metasfresh    文件:OFX1ToXML.java   
/**
 * Method init
 * @param br BufferedReader
 * @throws IOException
 */
public void init(BufferedReader br) throws IOException
{
    m_writer = new BufferedWriter(new PipedWriter(m_reader));
    String line = br.readLine();

    write("<?xml version=\"1.0\"?>\n");
    write("<?OFX ");
    while(line.indexOf('<') != 0)
    {
        if (line.length() > 0) 
        {
            write(line.replaceAll(":", "=\"") + "\" ");
        }
        line = br.readLine();
    }
    write("?>\n");

    while(line != null)
    {
        m_ofx += line + "\n";
        line = br.readLine();
    }
    br.close();

    new Thread(this).start();
}
项目:Java-Algorithms    文件:ResultWriterTest.java   
@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)));
}
项目:In-the-Box-Fork    文件:PipedWriterTest.java   
public PReader(PipedWriter pw) {
    try {
        pr = new PipedReader(pw);
    } catch (IOException e) {
        System.out.println("Exception setting up reader: "
                + e.toString());
    }
}
项目:In-the-Box-Fork    文件:PipedWriterTest.java   
/**
 * @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);
}
项目:In-the-Box-Fork    文件:PipedReaderTest.java   
public PWriter(PipedReader reader) {
    try {
        pw = new PipedWriter(reader);
    } catch (Exception e) {
        System.out.println("Couldn't create writer");
    }
}
项目:KJumpingCube    文件:Main.java   
/** Play jump61.  ARGS0 may consist of the single string
 *  '--display' to indicate that the game is played using a GUI. Prints
 *  a usage message if the arguments are wrong. */
public static void main(String[] args0) {
    CommandArgs args =
        new CommandArgs("--display{0,1}", args0);

    if (!args.ok()) {
        usage();
        return;
    }

    Game game;
    if (args.contains("--display")) {
        try {
            Writer trash = new FileWriter("/dev/null");
            PipedWriter commandWriter = new PipedWriter();
            PipedReader commandReader =
                new PipedReader(commandWriter, COMMAND_BUFFER_SIZE);
            game = new Game(commandReader, trash, trash, trash);
            Display display = new Display("Jump61", game, commandWriter);
            game.play();
        } catch (IOException excp) {
            game = null;
            System.err.println("Internal error");
            System.exit(1);
        }
    } else {
        Writer output = new OutputStreamWriter(System.out);
        game = new Game(new InputStreamReader(System.in),
                        output, output,
                        new OutputStreamWriter(System.err));
        System.exit(game.play());
    }
}
项目:scheme-droid    文件:IOTextArea.java   
/** has someone created a reader? **/

  protected void enableIO() {
    if (this.readEnd == null) {
      this.readEnd  = new PipedReader();
      this.writeEnd = new PipedWriter();
      try { readEnd.connect(writeEnd); }
      catch (IOException e) { e.printStackTrace(); }
    }}
项目:cn1    文件:PipedWriterTest.java   
public PReader(PipedWriter pw) {
    try {
        pr = new PipedReader(pw);
    } catch (IOException e) {
        System.out.println("Exception setting up reader: "
                + e.toString());
    }
}
项目:cn1    文件:PipedWriterTest.java   
/**
 * @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));
}
项目:cn1    文件:PipedWriterTest.java   
/**
 * @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));
}
项目:cn1    文件:PipedWriterTest.java   
/**
 * @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));
}
项目:cn1    文件:PipedWriterTest.java   
/**
 * @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());
    }
}
项目:cn1    文件:PipedReaderTest.java   
public PWriter(PipedReader reader) {
    try {
        pw = new PipedWriter(reader);
    } catch (Exception e) {
        System.out.println("Couldn't create writer");
    }
}
项目:commons-text    文件:CodePointTranslatorTest.java   
@Test
public void testAboveReturningNonNull() throws IOException {
  final NumericEntityEscaper numericEntityEscaper = NumericEntityEscaper.above(0);
  final UnicodeEscaper unicodeEscaper = new UnicodeEscaper();
  final String string = unicodeEscaper.toUtf16Escape(0);
  final PipedReader pipedReader = new PipedReader();
  final PipedWriter pipedWriter = new PipedWriter(pipedReader);

  assertThat(numericEntityEscaper.translate(string, 0, pipedWriter)).isEqualTo(1);
}