Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. String tempPath = "/tmp/" + label + ".zip";
  2.  
  3. File zipFile = new File(tempPath);
  4. zipFile.deleteOnExit();
  5. ZipOutputStream zos = null;
  6.  
  7. try {
  8. zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
  9.  
  10. for (/* loops through files to zip */) {
  11. InputStream is = methodToGetTheDocument();
  12. ZipEntry zipEntry = new ZipEntry(document.getLabel());
  13. zos.putNextEntry(zipEntry);
  14. byte[] bytes = new byte[2048];
  15. int count = is.read(bytes);
  16. while (count > -1) {
  17. zos.write(bytes, 0, count);
  18. count = is.read(bytes);
  19. }
  20. is.close();
  21. zos.closeEntry();
  22. }
  23. return ok(zipFile);
  24. } catch (Exception e) {
  25. return badRequest("Bad request");
  26. } finally {
  27. try {
  28. zos.close();
  29. } catch (Exception e) {
  30. e.printStackTrace();
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement