Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String tempPath = "/tmp/" + label + ".zip";
- File zipFile = new File(tempPath);
- zipFile.deleteOnExit();
- ZipOutputStream zos = null;
- try {
- zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
- for (/* loops through files to zip */) {
- InputStream is = methodToGetTheDocument();
- ZipEntry zipEntry = new ZipEntry(document.getLabel());
- zos.putNextEntry(zipEntry);
- byte[] bytes = new byte[2048];
- int count = is.read(bytes);
- while (count > -1) {
- zos.write(bytes, 0, count);
- count = is.read(bytes);
- }
- is.close();
- zos.closeEntry();
- }
- return ok(zipFile);
- } catch (Exception e) {
- return badRequest("Bad request");
- } finally {
- try {
- zos.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement