(File output, InputStream zipStream, String name)
| 137 | } |
| 138 | |
| 139 | public static void unzipFile(File output, InputStream zipStream, String name) throws IOException { |
| 140 | String canonicalDestinationDirPath = output.getCanonicalPath(); |
| 141 | File toWrite = new File(output, name); |
| 142 | String canonicalDestinationFile = toWrite.getCanonicalPath(); |
| 143 | if (!canonicalDestinationFile.startsWith(canonicalDestinationDirPath + File.separator)) { |
| 144 | throw new IOException("Entry is outside of the target dir: " + name); |
| 145 | } |
| 146 | |
| 147 | if (!FileHandler.createDir(toWrite.getParentFile())) |
| 148 | throw new IOException("Cannot create parent directory for: " + name); |
| 149 | |
| 150 | try (OutputStream out = new BufferedOutputStream(new FileOutputStream(toWrite), BUF_SIZE)) { |
| 151 | byte[] buffer = new byte[BUF_SIZE]; |
| 152 | int read; |
| 153 | while ((read = zipStream.read(buffer)) != -1) { |
| 154 | out.write(buffer, 0, read); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
no test coverage detected