private void unpack(JarEntry entry, File file) throws IOException { try (InputStream inputStream = this.jarFile.getInputStream(entry); OutputStream outputStream = new FileOutputStream(file)) { byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.flush(); } }
@Override public synchronized InputStream getInputStream(ZipEntry entry) throws IOException { if (entry instanceof JarEntry) { return this.entries.getInputStream((JarEntry) entry); } return getInputStream((entry != null) ? entry.getName() : null); }
/** * * @param jarFile * @param entry * @param file * @throws IOException */ private static void unpack(JarFile jarFile, JarEntry entry, File file) throws IOException { InputStream inputStream = jarFile.getInputStream(entry, RandomAccessData.ResourceAccess.ONCE); try { OutputStream outputStream = new FileOutputStream(file); try { byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead = -1; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.flush(); } finally { outputStream.close(); } } finally { inputStream.close(); } }
/** * * @param jarFile * @param entry * @param file * @throws IOException */ private static void unpack(JarFile jarFile, JarEntry entry, File file) throws IOException { InputStream inputStream = jarFile.getInputStream(entry, RandomAccessData.ResourceAccess.ONCE); try { OutputStream outputStream = new FileOutputStream(file); try { byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead = -1; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.flush(); } finally { outputStream.close(); } } finally { inputStream.close(); } }
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, JarEntryFilter filter, JarFileType type, Supplier<Manifest> manifestSupplier) throws IOException { super(rootFile.getFile()); this.rootFile = rootFile; this.pathFromRoot = pathFromRoot; CentralDirectoryParser parser = new CentralDirectoryParser(); this.entries = parser.addVisitor(new JarFileEntries(this, filter)); parser.addVisitor(centralDirectoryVisitor()); this.data = parser.parse(data, filter == null); this.type = type; this.manifestSupplier = (manifestSupplier != null) ? manifestSupplier : () -> { try (InputStream inputStream = getInputStream(MANIFEST_NAME)) { if (inputStream == null) { return null; } return new Manifest(inputStream); } catch (IOException ex) { throw new RuntimeException(ex); } }; }
@Override public InputStream getInputStream() throws IOException { if (this.jarFile == null) { throw FILE_NOT_FOUND_EXCEPTION; } if (this.jarEntryName.isEmpty() && this.jarFile.getType() == JarFile.JarFileType.DIRECT) { throw new IOException("no entry name specified"); } connect(); InputStream inputStream = (this.jarEntryName.isEmpty() ? this.jarFile.getData().getInputStream() : this.jarFile.getInputStream(this.jarEntry)); if (inputStream == null) { throwFileNotFound(this.jarEntryName, this.jarFile); } return inputStream; }