| 296 | } |
| 297 | |
| 298 | public static void readEntry(File zipfile, String entryname, Consumer<InputStream> v) throws IOException { |
| 299 | ZipFile file = new ZipFile(zipfile); |
| 300 | Throwable x = null; |
| 301 | |
| 302 | try { |
| 303 | Enumeration<? extends ZipEntry> entries = file.entries(); |
| 304 | while (entries.hasMoreElements()) { |
| 305 | ZipEntry entry = entries.nextElement(); |
| 306 | |
| 307 | if (entryname.equals(entry.getName())) { |
| 308 | InputStream in = file.getInputStream(entry); |
| 309 | v.accept(in); |
| 310 | } |
| 311 | } |
| 312 | } catch (Exception ex) { |
| 313 | x = ex.getCause(); |
| 314 | } finally { |
| 315 | file.close(); |
| 316 | } |
| 317 | |
| 318 | if (x != null) { |
| 319 | throw new IOException("Failed to read zip entry, however it has been closed safely.", x); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | public static void writeAll(File f, Object c) throws IOException { |
| 324 | f.getParentFile().mkdirs(); |