Search code examples
javaapache-camelblueprint-osgi

How to cut the first n bytes from the body in a camel blueprint?


I am routing and transforming some data with apache camel and want to cut the first n bytes of the body. So I will transform the body by reading the stream except the frist n bytes. Is there a smart way to do this in a camel blueprint?


Solution

  • A colleague gave me a good hint and I think this is the answer I was looking for:

    <convertBodyTo type="byte[]"/>
    <transform>
        <spel>#{T(java.util.Arrays).copyOfRange(body, n, body.length)}</spel>
    </transform>
    

    where n is the number of bytes I want to cut from the start of the ByteArrayOutputStream. I think this is a solution, isn't it?

    Certainly you have to build some checks and ExceptionHandling around it, but it worked for me.