Search in sources :

Example 21 with PipedReader

use of java.io.PipedReader in project commons-text by apache.

the class CodePointTranslatorTest method testAboveReturningNonNull.

@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);
}
Also used : PipedWriter(java.io.PipedWriter) PipedReader(java.io.PipedReader) Test(org.junit.Test)

Example 22 with PipedReader

use of java.io.PipedReader in project h2database by h2database.

the class CreateCluster method performTransfer.

private static void performTransfer(Statement statSource, String urlTarget, String user, String password, String serverList) throws SQLException {
    // Delete the target database first.
    try (Connection connTarget = DriverManager.getConnection(urlTarget + ";CLUSTER=''", user, password);
        Statement statTarget = connTarget.createStatement()) {
        statTarget.execute("DROP ALL OBJECTS DELETE FILES");
    }
    try (PipedReader pipeReader = new PipedReader()) {
        Future<?> threadFuture = startWriter(pipeReader, statSource);
        // Read data from pipe reader, restore on target.
        try (Connection connTarget = DriverManager.getConnection(urlTarget, user, password);
            Statement statTarget = connTarget.createStatement()) {
            RunScript.execute(connTarget, pipeReader);
            // Check if the writer encountered any exception
            try {
                threadFuture.get();
            } catch (ExecutionException ex) {
                throw new SQLException(ex.getCause());
            } catch (InterruptedException ex) {
                throw new SQLException(ex);
            }
            // set the cluster to the serverList on both databases
            statSource.executeUpdate("SET CLUSTER '" + serverList + "'");
            statTarget.executeUpdate("SET CLUSTER '" + serverList + "'");
        }
    } catch (IOException ex) {
        throw new SQLException(ex);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PipedReader(java.io.PipedReader)

Example 23 with PipedReader

use of java.io.PipedReader in project j2objc by google.

the class OldPipedWriterTest method test_write$CII.

public void test_write$CII() throws Exception {
    pw = new PipedWriter();
    try {
        pw.write(testBuf, 0, 5);
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    pw = new PipedWriter(new PipedReader());
    try {
        pw.write(testBuf, -1, 1);
        fail("Test 2: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        pw.write(testBuf, 0, -1);
        fail("Test 3: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        pw.write(testBuf, 5, testString.length());
        fail("Test 4: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    pw.close();
    pw = new PipedWriter();
    try {
        readerThread = new Thread(reader = new PReader(pw), "writeCII");
        readerThread.start();
        pw.write(testBuf, 0, testLength);
        pw.close();
        reader.read(testLength);
        assertTrue("Test 5: Characters read do not match the characters written.", Arrays.equals(testBuf, reader.buf));
    } catch (IOException e) {
        fail("Test 5: Unexpected IOException: " + e.getMessage());
    }
    readerThread.interrupt();
    try {
        pw.write(testBuf, 0, 5);
        fail("Test 6: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    reader.pr.close();
    try {
        pw.write(testBuf, 0, 5);
        fail("Test 7: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : PipedWriter(java.io.PipedWriter) IOException(java.io.IOException) PipedReader(java.io.PipedReader)

Example 24 with PipedReader

use of java.io.PipedReader in project j2objc by google.

the class OldPipedWriterTest method test_connectLjava_io_PipedReader.

public void test_connectLjava_io_PipedReader() throws Exception {
    PipedReader rd = new PipedReader();
    pw = new PipedWriter();
    try {
        pw.connect(rd);
    } catch (Exception e) {
        fail("Test 1: Unexpected exception when connecting: " + e.getLocalizedMessage());
    }
    readerThread = new Thread(reader = new PReader(rd), "connect");
    readerThread.start();
    try {
        pw.write(testBuf);
    } catch (IOException e) {
        fail("Test 2: Unexpected IOException when writing after connecting.");
    }
    assertEquals("Test 3: Incorrect character string received.", testString, reader.read(testLength));
    try {
        pw.connect(new PipedReader());
        fail("Test 4: IOException expected when reconnecting the writer.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : PipedWriter(java.io.PipedWriter) IOException(java.io.IOException) PipedReader(java.io.PipedReader) IOException(java.io.IOException)

Example 25 with PipedReader

use of java.io.PipedReader in project j2objc by google.

the class OldBufferedReaderTest method test_read$CII_Exception.

public void test_read$CII_Exception() throws Exception {
    br = new BufferedReader(new Support_StringReader(testString));
    try {
        br.read(new char[10], -1, 1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        br.read(new char[10], 0, -1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        br.read(new char[10], 10, 1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    // regression for HARMONY-831
    try {
        new BufferedReader(new PipedReader(), 9).read(new char[] {}, 7, 0);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }
}
Also used : BufferedReader(java.io.BufferedReader) PipedReader(java.io.PipedReader) Support_StringReader(tests.support.Support_StringReader)

Aggregations

PipedReader (java.io.PipedReader)27 PipedWriter (java.io.PipedWriter)22 IOException (java.io.IOException)15 BufferedReader (java.io.BufferedReader)5 StreamResult (javax.xml.transform.stream.StreamResult)3 Support_StringReader (tests.support.Support_StringReader)3 Writer (java.io.Writer)2 Templates (javax.xml.transform.Templates)2 Transformer (javax.xml.transform.Transformer)2 Test (org.junit.Test)2 ResourceConfiguration (com.oracle.svm.configure.config.ResourceConfiguration)1 JsonWriter (com.oracle.svm.configure.json.JsonWriter)1 ResourceConfigurationParser (com.oracle.svm.core.configure.ResourceConfigurationParser)1 ResourcesRegistry (com.oracle.svm.core.configure.ResourcesRegistry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CharArrayReader (java.io.CharArrayReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1