Search in sources :

Example 1 with InputStreamPayload

use of org.jclouds.io.payloads.InputStreamPayload in project camel by apache.

the class JcloudsPayloadConverter method toPayload.

@Converter
public static Payload toPayload(final InputStream is, Exchange exchange) throws IOException {
    InputStreamPayload payload = new InputStreamPayload(is);
    // only set the contentlength if possible
    if (is.markSupported()) {
        long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {

            @Override
            public InputStream getInput() throws IOException {
                return is;
            }
        });
        is.reset();
        payload.getContentMetadata().setContentLength(contentLength);
    }
    return payload;
}
Also used : InputStream(java.io.InputStream) InputStreamPayload(org.jclouds.io.payloads.InputStreamPayload) IOException(java.io.IOException) FallbackConverter(org.apache.camel.FallbackConverter) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter)

Example 2 with InputStreamPayload

use of org.jclouds.io.payloads.InputStreamPayload in project camel by apache.

the class JcloudsPayloadConverter method toPayload.

@Converter
public static Payload toPayload(final StreamSourceCache cache, Exchange exchange) throws IOException {
    long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {

        @Override
        public InputStream getInput() throws IOException {
            return cache.getInputStream();
        }
    });
    cache.reset();
    InputStreamPayload payload = new InputStreamPayload(cache.getInputStream());
    payload.getContentMetadata().setContentLength(contentLength);
    setContentMetadata(payload, exchange);
    return payload;
}
Also used : InputStream(java.io.InputStream) InputStreamPayload(org.jclouds.io.payloads.InputStreamPayload) IOException(java.io.IOException) FallbackConverter(org.apache.camel.FallbackConverter) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Converter (org.apache.camel.Converter)2 FallbackConverter (org.apache.camel.FallbackConverter)2 TypeConverter (org.apache.camel.TypeConverter)2 InputStreamPayload (org.jclouds.io.payloads.InputStreamPayload)2