Creates a single-entry zip file. @param input an uncompressed file @param pathWithinArchive the path within the archive @param output the new zip file it will be compressed into
(File input, String pathWithinArchive, File output)
| 153 | * @param output the new zip file it will be compressed into |
| 154 | */ |
| 155 | public static void zip(File input, String pathWithinArchive, File output) throws IOException { |
| 156 | try (ZipOutputStream zipStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(output)))) { |
| 157 | zipStream.setMethod(ZipOutputStream.DEFLATED); |
| 158 | zipStream.setLevel(9); |
| 159 | zipStream.putNextEntry(new ZipEntry(pathWithinArchive)); |
| 160 | try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(input))) { |
| 161 | copy(inputStream, zipStream); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** Copies one stream into the other. */ |
| 167 | private static void copy(InputStream input, OutputStream output) throws IOException { |