vendredi 31 août 2018

How to process on OutputStream revceived from a download API before return to client

After I called api InputStream downloadFiles(FileIDListPojo var1, String var2, String var3), I want to do some more actions before write the inputStream into servletOutputStream and return to client.

Basically I will send several requests, and combine them together into one response and return to client. You may wonder why I don't sent requests together, it's because I want to put each response stream into a folder (or zip) first then put the folders into one returned ZipOutputStream.

What I currently did is loop the procedures below for all requests.

  1. prepare a temp ByteArrayOutputStream tempOs = new ByteArrayOutputStream();

  2. add a zip folder to tempOs ZipOutputStream zipStream = new ZipOutputStream(tempOs);
    zipStream.putNextEntry(new ZipEntry("folder name.zip"));

  3. get inputStream from hue-drive and write it into tempOs input = hueDriveFileClient.downloadFiles(fileIDListPojo, sessionToken, encoding); IOUtils.copy(input, tempOs);
  4. write tempOs to response stream response.getOutputStream().write(tempOs.toByteArray());

Unfortunately I cannot get the correct zip file, it seems that files are not put into a folder, but written into one... So I want to ask if you can have a look and give some advice?




Aucun commentaire:

Enregistrer un commentaire