Search in sources :

Example 41 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project camel by apache.

the class CxfUtils method getStringFromInputStream.

public static String getStringFromInputStream(InputStream in) throws Exception {
    CachedOutputStream bos = new CachedOutputStream();
    IOUtils.copy(in, bos);
    in.close();
    bos.close();
    return bos.getOut().toString();
}
Also used : CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 42 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.

the class JAXRSAtomBookTest method copyIn.

private InputStream copyIn(InputStream in) throws Exception {
    try (CachedOutputStream bos = new CachedOutputStream()) {
        IOUtils.copyAndCloseInput(in, bos);
        in = bos.getInputStream();
        bos.close();
        return in;
    }
}
Also used : CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 43 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.

the class EngineLifecycleTest method getTestHtml.

private void getTestHtml() throws Exception {
    CachedOutputStream response = null;
    for (int i = 0; i < 10; i++) {
        try {
            HttpURLConnection httpConnection = getHttpConnection("http://localhost:" + PORT2 + "/test.html");
            httpConnection.connect();
            InputStream in = httpConnection.getInputStream();
            assertNotNull(in);
            response = new CachedOutputStream();
            IOUtils.copy(in, response);
            in.close();
            response.close();
            break;
        } catch (Exception ex) {
            response = null;
            Thread.sleep(2 * 1000);
        }
    }
    assertNotNull("Test doc can not be read", response);
    FileInputStream htmlFile = new FileInputStream("target/test-classes/org/apache/cxf/systest/http_jetty/test.html");
    CachedOutputStream html = new CachedOutputStream();
    IOUtils.copy(htmlFile, html);
    htmlFile.close();
    html.close();
    assertEquals("Can't get the right test html", html.toString(), response.toString());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileInputStream(java.io.FileInputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 44 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project carbon-business-process by wso2.

the class Utils method getAttachmentStream.

public static OutputStream getAttachmentStream(InputStream inputStream) throws IOException {
    if (inputStream != null) {
        CachedOutputStream cachedOutputStream = new CachedOutputStream();
        IOUtils.copy(inputStream, cachedOutputStream);
        cachedOutputStream.close();
        return cachedOutputStream.getOut();
    }
    return null;
}
Also used : CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 45 with CachedOutputStream

use of org.apache.cxf.io.CachedOutputStream in project tomee by apache.

the class AttachmentDataSource method cache.

public void cache(Message message) throws IOException {
    if (cache == null) {
        cache = new CachedOutputStream();
        AttachmentUtil.setStreamedAttachmentProperties(message, cache);
        try {
            IOUtils.copyAndCloseInput(ins, cache);
            cache.lockOutputStream();
            if (delegate != null) {
                delegate.setInputStream(cache.getInputStream());
            }
        } catch (CacheSizeExceededException | IOException cee) {
            cache.close();
            cache = null;
            throw cee;
        } finally {
            ins = null;
        }
    }
}
Also used : CacheSizeExceededException(org.apache.cxf.io.CacheSizeExceededException) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Aggregations

CachedOutputStream (org.apache.cxf.io.CachedOutputStream)105 InputStream (java.io.InputStream)38 IOException (java.io.IOException)35 Test (org.junit.Test)24 Message (org.apache.cxf.message.Message)22 OutputStream (java.io.OutputStream)18 Fault (org.apache.cxf.interceptor.Fault)18 MessageImpl (org.apache.cxf.message.MessageImpl)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 XMLStreamException (javax.xml.stream.XMLStreamException)10 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)10 PrintWriter (java.io.PrintWriter)8 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 StreamSource (javax.xml.transform.stream.StreamSource)6 Endpoint (org.apache.cxf.endpoint.Endpoint)6 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)6 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Source (javax.xml.transform.Source)5 ArrayList (java.util.ArrayList)4