简体   繁体   中英

Can a byte array be passed to an outbound file transport in mule ESB

I have a java component that is zipping a csv file and returning an array of bytes from a ByteArrayOutputStream. I'm attempting to pass this to a file transport to be written to the OS. A file is written to the OS, but Windows reports that the file is invalid when I attempt to open it. First, is it possible to send a byte array to the file transport? If so, then I think I will likely have to post another question about what I am doing wrong zipping the contents of the csv...

Here's a snippet of the 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;

Here's the relevant part of my flow:

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

I would suggest using the ZipTransformer class @anupambhusari submitted for this question:

Mule Zip File and send zipped file towards FTP server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM