Search in sources :

Example 6 with PipedReader

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

the class XsltStylesheet method retryXsltTransformation.

private String retryXsltTransformation(ThreadContext context, IRubyObject[] args, DOMSource domSource, NokogiriXsltErrorListener elistener) throws TransformerException, IOException {
    Templates templates = getTemplatesFromStreamSource();
    Transformer transf = templates.newTransformer();
    transf.setErrorListener(elistener);
    if (args.length > 1) {
        addParametersToTransformer(context, transf, args[1]);
    }
    PipedWriter pwriter = new PipedWriter();
    PipedReader preader = new PipedReader();
    pwriter.connect(preader);
    StreamResult result = new StreamResult(pwriter);
    transf.transform(domSource, result);
    char[] cbuf = new char[1024];
    int len = preader.read(cbuf, 0, 1024);
    StringBuilder builder = new StringBuilder();
    builder.append(CharBuffer.wrap(cbuf, 0, len));
    // judge from the first chunk
    htmlish = isHtml(builder.toString());
    while (len == 1024) {
        len = preader.read(cbuf, 0, 1024);
        if (len > 0) {
            builder.append(CharBuffer.wrap(cbuf, 0, len));
        }
    }
    preader.close();
    pwriter.close();
    return builder.toString();
}
Also used : PipedWriter(java.io.PipedWriter) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Templates(javax.xml.transform.Templates) PipedReader(java.io.PipedReader)

Example 7 with PipedReader

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

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 8 with PipedReader

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

the class OldPipedWriterTest method test_ConstructorLjava_io_PipedReader.

public void test_ConstructorLjava_io_PipedReader() throws Exception {
    PipedReader rd = new PipedReader();
    try {
        pw = new PipedWriter(rd);
    } catch (Exception e) {
        fail("Test 1: Construtor failed:" + e.getMessage());
    }
    readerThread = new Thread(reader = new PReader(rd), "Constructor(Reader)");
    readerThread.start();
    try {
        pw.write(testBuf);
    } catch (Exception e) {
        fail("Test 2: Could not write to the constructed writer: " + e.getMessage());
    }
    pw.close();
    assertEquals("Test 3: Incorrect character string received.", testString, reader.read(testLength));
    rd = new PipedReader(new PipedWriter());
    try {
        pw = new PipedWriter(rd);
        fail("Test 4: IOException expected because the reader is already connected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : PipedWriter(java.io.PipedWriter) IOException(java.io.IOException) PipedReader(java.io.PipedReader) IOException(java.io.IOException)

Example 9 with PipedReader

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

the class OldPipedWriterTest method test_close.

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

Example 10 with PipedReader

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

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)

Aggregations

PipedReader (java.io.PipedReader)19 PipedWriter (java.io.PipedWriter)16 IOException (java.io.IOException)11 BufferedReader (java.io.BufferedReader)3 Support_StringReader (tests.support.Support_StringReader)3 Templates (javax.xml.transform.Templates)2 Transformer (javax.xml.transform.Transformer)2 StreamResult (javax.xml.transform.stream.StreamResult)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CharArrayReader (java.io.CharArrayReader)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 ScriptContext (javax.script.ScriptContext)1 JTextArea (javax.swing.JTextArea)1 PipeListener (jmri.util.PipeListener)1 BOSHClientRequestListener (org.igniterealtime.jbosh.BOSHClientRequestListener)1 BOSHClientResponseListener (org.igniterealtime.jbosh.BOSHClientResponseListener)1 BOSHException (org.igniterealtime.jbosh.BOSHException)1