Available since Camel 2.18.0

The Tar File Data Format is a message compression and de-compression format. Messages can be marshalled (compressed) to Tar Files containing a single entry, and Tar Files containing a single entry can be unmarshalled (decompressed) to the original file contents.

There is also a aggregation strategy that can aggregate multiple messages into a single Tar File.

TarFile Options

The Tar File dataformat supports 1 options which are listed below.

NameDefaultJava TypeDescription

usingIterator

false

Boolean

If the tar file has more then one entry the setting this option to true allows to work with the splitter EIP to split the data using an iterator in a streaming mode.

Marshal

In this example we marshal a regular text/XML payload to a compressed payload using Tar File compression, and send it to an ActiveMQ queue called MY_QUEUE.

 

The name of the Tar entry inside the created Tar File is based on the incoming CamelFileName message header, which is the standard message header used by the file component. Additionally, the outgoing CamelFileNamemessage header is automatically set to the value of the incoming CamelFileName message header, with the ".tar" suffix. So for example, if the following route finds a file named "test.txt" in the input directory, the output will be a Tar File named "test.txt.tar" containing a single Tar entry named "test.txt":

If there is no incoming CamelFileName message header (for example, if the file component is not the consumer), then the message ID is used by default, and since the message ID is normally a unique generated ID, you will end up with filenames like ID-MACHINENAME-2443-1211718892437-1-0.tar. If you want to override this behavior, then you can set the value of the CamelFileName header explicitly in your route:

 

This route would result in a Tar File named "report.txt.tar" in the output directory, containing a single Tar entry named "report.txt".

 

UUnmarshal

In this example we unmarshal a Tar File payload from an ActiveMQ queue called MY_QUEUE to its original format, and forward it for processing to the UnTarpedMessageProcessor.

If the Tar File has more then one entry, the usingIterator option of TarFileDataFormat to be true, and you can use splitter to do the further work.

 

 

Or you can use the TarSplitter as an expression for splitter directly like this

Aggregate

Please note that this aggregation strategy requires eager completion check to work properly.

 

In this example we aggregate all text files found in the input directory into a single Tar File that is stored in the output directory. 

The outgoing CamelFileName message header is created using java.io.File.createTempFile, with the ".tar" suffix. If you want to override this behavior, then you can set the value of the CamelFileName header explicitly in your route:

 

 

Dependencies

To use Tar Files in your camel routes you need to add a dependency on camel-tarfile which implements this data format.

If you use Maven you can just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).


© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram