Search in sources :

Example 6 with PipedWriter

use of java.io.PipedWriter 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)

Example 7 with PipedWriter

use of java.io.PipedWriter in project nokogiri by sparklemotion.

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(len);
    builder.append(cbuf, 0, len);
    // judge from the first chunk
    htmlish = isHtml(builder);
    while (len == 1024) {
        len = preader.read(cbuf, 0, 1024);
        if (len > 0) {
            builder.append(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 8 with PipedWriter

use of java.io.PipedWriter 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 9 with PipedWriter

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

the class OldPipedWriterTest method test_Constructor.

public void test_Constructor() {
    pw = new PipedWriter();
    assertNotNull(pw);
    try {
        pw.close();
    } catch (IOException e) {
        fail("Unexpeceted IOException.");
    }
}
Also used : PipedWriter(java.io.PipedWriter) IOException(java.io.IOException)

Example 10 with PipedWriter

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

the class OldPipedWriterTest method test_flush.

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

Aggregations

PipedWriter (java.io.PipedWriter)23 PipedReader (java.io.PipedReader)16 IOException (java.io.IOException)14 Templates (javax.xml.transform.Templates)2 Transformer (javax.xml.transform.Transformer)2 StreamResult (javax.xml.transform.stream.StreamResult)2 BufferedWriter (java.io.BufferedWriter)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 BOSHMessageEvent (org.igniterealtime.jbosh.BOSHMessageEvent)1 SmackException (org.jivesoftware.smack.SmackException)1 ConnectionException (org.jivesoftware.smack.SmackException.ConnectionException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 StreamErrorException (org.jivesoftware.smack.XMPPException.StreamErrorException)1