Package org.apache.camel

Examples of org.apache.camel.StreamCache


        assertEquals("The converted message is wrong", MESSAGE, message);
    }

    public void testConvertToStreamCacheStreamSource() throws Exception {
        StreamSource source = new StreamSource(getTestFileStream());
        StreamCache cache = StreamCacheConverter.convertToStreamCache(source, exchange);
        //assert re-readability of the cached StreamSource
        XmlConverter converter = new XmlConverter();
        assertNotNull(converter.toString((Source)cache, null));
        cache.reset();
        assertNotNull(converter.toString((Source)cache, null));
    }
View Full Code Here


        }
    }

    public void testConvertToSerializable() throws Exception {
        InputStream is = getTestFileStream();
        StreamCache cache = StreamCacheConverter.convertToStreamCache(is, exchange);
        Serializable ser = StreamCacheConverter.convertToSerializable(cache, exchange);
        assertNotNull(ser);
    }
View Full Code Here

        assertNotNull(ser);
    }

    public void testConvertToByteArray() throws Exception {
        InputStream is = getTestFileStream();
        StreamCache cache = StreamCacheConverter.convertToStreamCache(is, exchange);
        byte[] bytes = StreamCacheConverter.convertToByteArray(cache, exchange);
        assertNotNull(bytes);
    }
View Full Code Here

        File file = new File("./target/cachedir");
        String[] files = file.list();
        assertEquals("we should have a temp file", files.length, 1);
        assertTrue("The file name should start with cos" , files[0].startsWith("cos"));
       
        StreamCache cache = cos.getStreamCache();
        assertTrue("Should get the FileInputStreamCache", cache instanceof FileInputStreamCache);
        String temp = toString((InputStream)cache);

        ((InputStream)cache).close();
        assertEquals("we should have a temp file", files.length, 1);
        assertEquals("Cached a wrong file", temp, TEST_STRING);
        exchange.getUnitOfWork().done(exchange);

        try {
            cache.reset();
            // The stream is closed, so the temp file is gone.
            fail("we expect the exception here");
        } catch (Exception exception) {
            // do nothing
        }
View Full Code Here

        File file = new File("./target/cachedir");
        String[] files = file.list();
        assertEquals("we should have a temp file", files.length, 1);
        assertTrue("The file name should start with cos" , files[0].startsWith("cos"));
       
        StreamCache cache = cos.getStreamCache();
        assertTrue("Should get the FileInputStreamCache", cache instanceof FileInputStreamCache);
        String temp = toString((InputStream)cache);
        assertEquals("Cached a wrong file", temp, TEST_STRING);
        cache.reset();
        temp = toString((InputStream)cache);
        assertEquals("Cached a wrong file", temp, TEST_STRING);       
        exchange.getUnitOfWork().done(exchange);
        assertEquals("we should have a temp file", files.length, 1);
        ((InputStream)cache).close();
View Full Code Here

        File file = new File("./target/cachedir");
        String[] files = file.list();

        assertEquals("we should have no temp file", files.length, 0);
        StreamCache cache = cos.getStreamCache();
        assertTrue("Should get the InputStreamCache", cache instanceof InputStreamCache);
        String temp = IOConverter.toString((InputStream)cache, null);
        assertEquals("Cached a wrong file", temp, TEST_STRING);
    }
View Full Code Here

        File file = new File("./target/cachedir");
        String[] files = file.list();

        assertEquals("we should have no temp file", files.length, 0);
        StreamCache cache = cos.getStreamCache();
        assertTrue("Should get the InputStreamCache", cache instanceof InputStreamCache);
        String temp = IOConverter.toString((InputStream)cache, null);
        assertEquals("Cached a wrong file", temp, TEST_STRING);

        exchange.getUnitOfWork().done(exchange);
View Full Code Here

        template.sendBody("direct:a", message);

        assertMockEndpointsSatisfied();

        Exchange exchange = a.getExchanges().get(0);
        StreamCache cache = assertIsInstanceOf(StreamCache.class, exchange.getIn().getBody());
        assertNotNull(cache);

        assertNotSame(message, cache);
    }
View Full Code Here

        MessageHelper.resetStreamCache(null);
        MessageHelper.resetStreamCache(message);
       
        // handle StreamCache
        final ValueHolder<Boolean> reset = new ValueHolder<Boolean>(Boolean.FALSE);
        message.setBody(new StreamCache() {
            public void reset() {
                reset.set(Boolean.TRUE);
            }

            public void writeTo(OutputStream os) throws IOException {
View Full Code Here

                // just use a to string of the future object
                return message.getBody().toString();
            }
        }

        StreamCache newBody = message.getBody(StreamCache.class);
        if (newBody != null) {
            message.setBody(newBody);
        }

        Object answer = message.getBody(String.class);
        if (answer == null) {
            answer = message.getBody();
        }

        if (newBody != null) {
            // Reset the StreamCache
            newBody.reset();
        }
        return answer;
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.StreamCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.