Examples of StreamCache


Examples of org.apache.camel.StreamCache

        CachedOutputStream cos = new CachedOutputStream();
        cos.setOutputDir(file);
        cos.write(TEST_STRING.getBytes("UTF-8"));       
        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);
        assertEquals("Cached a wrong file", temp, TEST_STRING);
    }
View Full Code Here

Examples of org.apache.camel.StreamCache

    public static String extractBodyAsString(Message message) {
        if (message == null) {
            return null;
        }

        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 InputStreamCache
            newBody.reset();
        }

        return answer != null ? answer.toString() : null;
    }
View Full Code Here

Examples of org.apache.camel.StreamCache

                // 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

Examples of org.apache.camel.StreamCache

        this.exchange = new DefaultExchange(context);
    }
   
    public void testConvertToStreamCache() throws Exception {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(MESSAGE.getBytes());
        StreamCache streamCache = converter.convertToStreamCache(new SAXSource(new InputSource(inputStream)), exchange);
        String message = exchange.getContext().getTypeConverter().convertTo(String.class, streamCache);
        assertNotNull(message);
        assertEquals("The converted message is wrong", MESSAGE, message);
    }
View Full Code Here

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 = converter.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

Examples of org.apache.camel.StreamCache

        }
    }

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

Examples of org.apache.camel.StreamCache

        assertNotNull(ser);
    }

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

Examples of org.apache.camel.StreamCache

        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

Examples of org.apache.camel.StreamCache

        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

Examples of org.apache.camel.StreamCache

        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
TOP
Copyright © 2018 www.massapi.com. 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.