[英]Can a byte array be passed to an outbound file transport in mule ESB
我有一個Java組件,正在壓縮一個csv文件並從ByteArrayOutputStream返回一個字節數組。 我正在嘗試將其傳遞給要寫入操作系統的文件傳輸。 文件已寫入操作系統,但Windows報告我嘗試打開該文件時該文件無效。 首先,是否可以將字節數組發送到文件傳輸? 如果是這樣,那么我想我可能將不得不發布另一個問題,詢問我在壓縮CSV內容時做錯了什么...
這是Java的代碼段:
List<String> csvFiles = (List<String>)message.getPayload();
InputStream originalFile = null;
ByteArrayOutputStream dest = new ByteArrayOutputStream();
ZipOutputStream out = new ZipOutputStream(dest);
File temp = new File("users.csv");
originalFile = new
ByteArrayInputStream((csvFiles.get(0)).toString().getBytes());
ZipEntry entry = new ZipEntry(temp.getPath());
out.putNextEntry(entry);
int count;
while((count = originalFile.read()) != -1) {
out.write(count);
}
originalFile.close();
byte[] zipFileByteArray = dest.toByteArray();
out.close();
dest.close();
return zipFileByteArray;
這是我流程的相關部分:
<flow name="zip-csv">
<component class="edu.ucdavis.iet.canvas.ZipFiles" doc:name="Java"/>
<file:outbound-endpoint path="${message_archive.dir}" responseTimeout="10000" doc:name="save message to dir" outputPattern="temp.zip"/>
</flow>
我建議使用針對此問題提交的ZipTransformer類@anupambhusari:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.