问题
I was doing some sort of POC with Mule Gzip compressor and de-compressor.. My Mule flow is following
<flow name="GZipCompress" doc:name="GZipFlow1">
<file:inbound-endpoint path="E:\backup\test" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern="anirban.doc" caseSensitive="false"/>
</file:inbound-endpoint>
<string-to-byte-array-transformer doc:name="String to Byte Array"/>
<gzip-compress-transformer/>
<file:outbound-endpoint path="E:\backup\test\ss" responseTimeout="10000" doc:name="File"/>
</flow>
<flow name="GZipUnCompress" doc:name="GZipFlow2">
<file:inbound-endpoint path="E:\backup\test\ss" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern="anirban.doc" caseSensitive="false"/>
</file:inbound-endpoint>
<gzip-uncompress-transformer />
<byte-array-to-string-transformer />
<file:outbound-endpoint path="E:\backup\test\ss\New folder" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>
Now the issue is I have a file anirban.doc which is around 80.0 KB before compression .. When I put the file in the folder for compression, file inbound of GZipCompress flow picks it up and compress it .. After compression the file size gets around 20 KB which is fine .. Now when I try to unCompress the file using GZipUnCompress flow , I get the file back in output folder of file outbound endpoint GZipUnCompress flow .. And this time the so called uncompress file is of size 96.0 KB .. and when I try to open the file I get binary format .. So my question is how can I get the uncompressed file back to same as original file size and I can open it and read it and not in binary form but as same original content .. Is this the right way I am compressing and decompressing a file/payload ..
回答1:
If I remove the string-to-byte-array-transformer
(which is useless and even counter productive: keep bytes as much as possible), then GZipCompress
works perfectly fine: it creates a valid gzipped file in the output dir.
来源:https://stackoverflow.com/questions/25771002/how-to-compress-decompress-payload-in-mule-and-get-back-original-payload