2016-06-13 20 views
0

我有一個java組件壓縮csv文件並從ByteArrayOutputStream返回一個字節數組。我試圖將它傳遞給文件傳輸器以寫入操作系統。一個文件被寫入操作系統,但是當我嘗試打開文件時,Windows報告文件無效。首先,是否可以向文件傳輸發送一個字節數組?如果是這樣的話,我想我可能將不得不發佈什麼,我做錯了荏苒的csv的內容中另一個問題...可以將一個字節數組傳遞到出站文件傳輸騾ESB

下面是在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> 
+2

猜測你在訪問dest.toByteArray()之前缺少'out.flush()'。 – geert3

+0

不幸的是,這並沒有奏效。謝謝,不過。 – GarySharpe

+2

@ geert3 @GarySharpe與之前的'out.close()'不同的是'out.flush()'。您需要關閉ZIP流才能進行適當的校驗和計算,以便計算並變成可刷新的,在緩衝區頂部刷新「stuff」。 – GPI

回答