如何在Mule中压缩/解压缩有效载荷并取回原始有效载荷 [英] How to Compress/Decompress payload in Mule and get back original payload

查看:127
本文介绍了如何在Mule中压缩/解压缩有效载荷并取回原始有效载荷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mule Gzip压缩器和解压缩器进行某种POC.我的Mule流如下

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>

现在的问题是我有一个文件 anirban.doc ,压缩前约为 80.0 KB .压缩后的文件大小为 20 KB .这很好..现在,当我尝试使用 GZipUnCompress 取消压缩文件时,我将文件放回文件出站终结点 GZipUnCompress 流的输出文件夹中.这一次,所谓的解压缩文件的大小为 96.0 KB ..,当我尝试打开文件我得到的是二进制格式..所以我的问题是如何将未压缩的文件恢复为与原始文件的大小相同,我可以打开并读取它,而不是以二进制形式而是相同的原始内容来读取.正确的方式来压缩和解压缩文件/有效载荷..

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

推荐答案

如果我删除了string-to-byte-array-transformer(这是无用的,甚至会产生反作用:尽可能多地保留字节),那么GZipCompress的工作就很好:在输出目录中创建一个有效的压缩文件.

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.

这篇关于如何在Mule中压缩/解压缩有效载荷并取回原始有效载荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆