private static File getEmbeddedZipFile(File embeddingZip, String[] pathes) throws IOException { File embedded = getEmbbededZipFile(embeddingZip, pathes[0]); if (pathes.length > 1) { return getEmbeddedZipFile(embedded, Arrays.copyOfRange(pathes, 1, pathes.length)); } else { return embedded; } }
/** * In contrast to the super class this method provides the name of the * ZIP file. * * @return the string */ @Override public String toString() { return "ZipFile '" + getName() + "'"; }
/** * Instantiates a new detailed zip file. * * @param file the file * @param mode the mode * @param charset the charset * @throws IOException Signals that an I/O exception has occurred. */ public NestedZipFile(File file, int mode, Charset charset) throws IOException { super(getEmbeddedZipFile(file), mode, charset); }
private static Collection<String> readElementsFromArchive(File archive, String archiveDir) throws IOException { Collection<String> elements = new ArrayList<>(); try (ZipFile zipFile = new NestedZipFile(archive)) { String relPath = archiveDir.startsWith("/") ? archiveDir.substring(1) : archiveDir; Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String name = entry.getName(); if (name.startsWith(relPath)) { elements.add(name.substring(relPath.length())); } } LOG.trace("{} element(s) read from {}.", elements.size(), archive); return elements; } }
private static File getEmbeddedZipFile(File file) throws IOException { String path = file.getPath(); if (path.contains("!")) { String[] pathes = path.split("!"); return getEmbeddedZipFile(new File(pathes[0]), Arrays.copyOfRange(pathes, 1, pathes.length)); } return file; }
/** * Gets the zip file. * * @return the zip file * * @throws IOException * Signals that an I/O exception has occurred. */ public ZipFile getZipFile() throws IOException { try { return new NestedZipFile(this.getFileArchiv()); } catch (IOException ioe) { throw new IOException("can't get zip file \"" + this.getFileArchiv() + '"', ioe); } }
private static File getEmbbededZipFile(File file, String name) throws IOException { String normalizedName = FilenameUtils.separatorsToUnix(name.substring(1)); try (ZipFile zipFile = new ZipFile(file)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (normalizedName.equals(entry.getName())) { return getEmbeddedZipFile(zipFile, entry); } } } throw new FileNotFoundException("entry '" + name + "' not found in " + file); }