Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. private Response ActionDownloadSingleFile(InputStream fis) {
  2. Response response = null;
  3. response = newChunkedResponse(Response.Status.OK, "application/octet-stream",fis);
  4. response.addHeader("Content-Disposition", "attachment; filename="+"my.zip");
  5. return response;
  6. }
  7.  
  8. public static void zip(String[] files, String zipFile) throws IOException {
  9. BufferedInputStream origin = null;
  10. ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
  11. try {
  12. byte data[] = new byte[BUFFER_SIZE];
  13.  
  14. for (int i = 0; i < files.length; i++) {
  15. FileInputStream fi = new FileInputStream(files[i]);
  16. origin = new BufferedInputStream(fi, BUFFER_SIZE);
  17. try {
  18. ZipEntry entry = new ZipEntry(files[i].substring(files[i].lastIndexOf("/") + 1));
  19. out.putNextEntry(entry);
  20. int count;
  21. while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
  22. out.write(data, 0, count);
  23. }
  24. }
  25. finally {
  26. origin.close();
  27. }
  28. }
  29. }
  30. finally {
  31. out.close();
  32. }
  33. }
  34.  
  35. File file= new File("my.zip");
  36. FileInputStream fis = null;
  37. try
  38. {
  39. fis = new FileInputStream(file);
  40. } catch (FileNotFoundException ex)
  41. {
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement