| 43 | private static final int BUF_SIZE = 16384; // "big" |
| 44 | |
| 45 | public static String zip(File input) throws IOException { |
| 46 | try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
| 47 | try (ZipOutputStream zos = new ZipOutputStream(bos)) { |
| 48 | if (input.isDirectory()) { |
| 49 | addToZip(input.getAbsolutePath(), zos, input); |
| 50 | } else { |
| 51 | addToZip(input.getParentFile().getAbsolutePath(), zos, input); |
| 52 | } |
| 53 | } |
| 54 | return Base64.getEncoder().encodeToString(bos.toByteArray()); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | private static void addToZip(String basePath, ZipOutputStream zos, File toAdd) |
| 59 | throws IOException { |