List of usage examples for java.util.zip ZipInputStream getNextEntry
public ZipEntry getNextEntry() throws IOException
From source file:com.amazonaws.eclipse.elasticbeanstalk.git.AWSGitPushCommand.java
private void extractZipFile(File zipFile, File destination) throws IOException { int BUFFER = 2048; FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); BufferedOutputStream dest = null; try {/*w w w . ja v a 2 s . com*/ ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { int count; byte data[] = new byte[BUFFER]; // write the files to the disk if (entry.isDirectory()) continue; File entryFile = new File(destination, entry.getName()); if (!entryFile.getParentFile().exists()) { entryFile.getParentFile().mkdirs(); } FileOutputStream fos = new FileOutputStream(entryFile); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); } } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(zis); IOUtils.closeQuietly(dest); } }
From source file:com.mcleodmoores.mvn.natives.UnpackDependenciesMojo.java
private void gatherNames(final Artifact artifact, final Map<String, Set<Artifact>> names) throws MojoFailureException { getLog().debug("Scanning " + ArtifactUtils.key(artifact)); check(artifact, (new IOCallback<InputStream, Boolean>(open(artifact)) { @Override//from w w w.ja v a2s . com protected Boolean apply(final InputStream input) throws IOException { final ZipInputStream zip = new ZipInputStream(new BufferedInputStream(input)); ZipEntry entry; while ((entry = zip.getNextEntry()) != null) { gatherName(artifact, entry.getName(), names); } return Boolean.TRUE; } }).call(new MojoLoggingErrorCallback(this))); }
From source file:cpcc.vvrte.services.db.DownloadServiceTest.java
@Test public void shouldGetAllVirtualVehicles() throws IOException { byte[] actual = sut.getAllVirtualVehicles(); ByteArrayInputStream bis = new ByteArrayInputStream(actual); ZipInputStream zis = new ZipInputStream(bis, Charset.forName("UTF-8")); ZipEntry entry = zis.getNextEntry(); assertThat(entry).isNotNull();/*from w w w . j a va 2s.co m*/ assertThat(entry.getName()).isEqualTo(VV_ONE_UUID + "/"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_ONE_UUID + "/vv.properties"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); Properties actualProps = new Properties(); actualProps.load(zis); assertThat(actualProps.getProperty("api-version")).isEqualTo(Integer.toString(VV_ONE_API_VERSION)); assertThat(actualProps.getProperty("end-time")).isEqualTo(sdf.format(VV_ONE_END_TIME)); assertThat(actualProps.getProperty("name")).isEqualTo(VV_ONE_NAME); assertThat(actualProps.getProperty("start-time")).isEqualTo(VV_ONE_START_TIME); assertThat(actualProps.getProperty("state")).isEqualTo(VV_ONE_STATE.name()); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_ONE_UUID + "/code.js"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); assertThat(IOUtils.toString(zis)).isEqualTo(VV_ONE_CODE); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_ONE_UUID + "/state-info.txt"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); assertThat(IOUtils.toString(zis)).isEqualTo(VV_ONE_STATE_INFO); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_ONE_UUID + "/storage/"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_TWO_UUID + "/"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_TWO_UUID + "/vv.properties"); actualProps = new Properties(); actualProps.load(zis); assertThat(actualProps.getProperty("api-version")).isEqualTo(Integer.toString(VV_TWO_API_VERSION)); assertThat(actualProps.getProperty("end-time")).isEqualTo(VV_TWO_END_TIME_STR); assertThat(actualProps.getProperty("name")).isEqualTo(VV_TWO_NAME); assertThat(actualProps.getProperty("start-time")).isEqualTo(sdf.format(VV_TWO_START_TIME)); assertThat(actualProps.getProperty("state")).isEqualTo(VV_TWO_STATE.name()); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_TWO_UUID + "/code.js"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); assertThat(IOUtils.toString(zis)).isEqualTo(VV_TWO_CODE); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_TWO_UUID + "/continuation.dat"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); assertThat(IOUtils.toByteArray(zis)).isEqualTo(VV_TWO_CONTINUATION); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_TWO_UUID + "/storage/"); assertThat(entry.getTime()).isEqualTo(CURRENT_TIME); entry = zis.getNextEntry(); assertThat(entry).isNotNull(); assertThat(entry.getName()).isEqualTo(VV_TWO_UUID + "/storage/itemOne1.json"); assertThat(entry.getTime()).isEqualTo(ITEM_ONE_1_TIME.getTime()); assertThat(IOUtils.toByteArray(zis)).isEqualTo(ITEM_ONE_1_CONTENT); }
From source file:com.formkiq.core.service.ArchiveServiceImpl.java
@Override public ArchiveDTO extractJSONFromZipFile(final byte[] bytes) { ArchiveDTO archive = new ArchiveDTO(); ByteArrayInputStream is = new ByteArrayInputStream(bytes); ZipInputStream zipStream = new ZipInputStream(is); try {/* ww w.jav a2 s . c o m*/ ZipEntry entry = null; while ((entry = zipStream.getNextEntry()) != null) { String filename = entry.getName(); if (filename.endsWith(".form")) { String data = IOUtils.toString(zipStream, CHARSET_UTF8); archive.addForm(this.jsonService.readValue(data, FormJSON.class)); } else if (filename.endsWith(".workflow")) { String data = IOUtils.toString(zipStream, CHARSET_UTF8); archive.setWorkflow(this.jsonService.readValue(data, Workflow.class)); } else if (filename.endsWith(".pdf")) { byte[] data = IOUtils.toByteArray(zipStream); archive.addPDF(filename, data); } else if (filename.endsWith(".signature")) { String s = filename.replaceAll("\\.signature", ""); byte[] data = IOUtils.toByteArray(zipStream); archive.addSignature(s, data); } else if (filename.endsWith(".route")) { String data = IOUtils.toString(zipStream, CHARSET_UTF8); archive.addRoute(this.jsonService.readValue(data, WorkflowRoute.class)); } else { byte[] data = IOUtils.toByteArray(zipStream); archive.addObject(filename, data); } } archive.finish(); } catch (IOException e) { LOG.log(Level.WARNING, e.getMessage(), e); throw new InvalidRequestBodyException(); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(zipStream); } return archive; }
From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java
private void install(Context context, File file, File targetDirectory) throws Throwable { sendBroadcast(context, STATE_INSTALL, 0); InputStream input = null;//from w ww. ja va 2 s . c o m ZipInputStream zip = null; try { zip = new ZipInputStream(input = new FileInputStream(file)); ZipEntry entry; int totalEntries = 0; while (zip.getNextEntry() != null) { totalEntries++; } zip.close(); input.close(); zip = new ZipInputStream(input = new FileInputStream(file)); int position = 0; while ((entry = zip.getNextEntry()) != null) { if (entry.isDirectory()) { final File directory = new File(targetDirectory, entry.getName()); if (!directory.isDirectory() && !directory.mkdirs()) { throw new IOException("Cannot create directory: " + directory.getAbsolutePath()); } } else { install(targetDirectory, entry.getName(), zip); } sendBroadcast(context, STATE_INSTALL, ((float) ++position / (float) totalEntries) * 0.99f); } } finally { if (zip != null) { try { zip.close(); } catch (IOException ignored) { } } if (input != null) { try { input.close(); } catch (IOException ignored) { } } } onInstallComplete(context); sendBroadcast(context, STATE_INSTALL, 1); }
From source file:de.micromata.genome.db.jpa.genomecore.chronos.JobStoreTest.java
License:asdf
public void findClassPathInJars() { try {/* w ww .j a v a2 s . c o m*/ Iterator it = FileUtils.iterateFiles(new File("."), new String[] { "jar" }, true); for (; it.hasNext();) { File f = (File) it.next(); ZipInputStream zf = new ZipInputStream(new FileInputStream(f)); ZipEntry ze; while ((ze = zf.getNextEntry()) != null) { String name = ze.getName(); if (name.startsWith("org/objectweb/asm") == true) { System.out.println("Found: " + f.getCanonicalPath()); zf.closeEntry(); break; } zf.closeEntry(); } zf.close(); } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.xpn.xwiki.plugin.zipexplorer.ZipExplorerPlugin.java
/** * @param document the document containing the ZIP file as an attachment * @param attachmentName the name under which the ZIP file is attached in the document * @param context not used// w w w.ja va2s.c o m * @return the list of file entries in the ZIP file attached under the passed attachment name inside the passed * document * @see com.xpn.xwiki.plugin.zipexplorer.ZipExplorerPluginAPI#getFileList */ public List<String> getFileList(Document document, String attachmentName, XWikiContext context) { List<String> zipList = new ArrayList<String>(); Attachment attachment = document.getAttachment(attachmentName); InputStream stream = null; try { stream = new ByteArrayInputStream(attachment.getContent()); if (isZipFile(stream)) { ZipInputStream zis = new ZipInputStream(stream); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { zipList.add(entry.getName()); } } } catch (XWikiException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return zipList; }
From source file:org.talend.license.LicenseRetriver.java
Collection<File> checkout(final String version, final File root, final String url) { try {// w w w .ja va 2 s . c o m return connector.doGet(url, new ResponseHandler<Collection<File>>() { public Collection<File> handleResponse(HttpResponse response) throws ClientProtocolException, IOException { Collection<File> files = new LinkedList<File>(); InputStream stream = response.getEntity().getContent(); ZipInputStream zip = new ZipInputStream(stream); String regex = Configer.getLicenseFile().replaceAll("%version", version); Pattern pattern = Pattern.compile(regex); while (true) { ZipEntry entry = zip.getNextEntry(); if (null == entry) { break; } try { String name = entry.getName(); Matcher matcher = pattern.matcher(name); if (matcher.find()) { int count = matcher.groupCount(); String fname = null; for (int i = 1; i <= count; i++) { fname = matcher.group(i); if (StringUtils.isEmpty(fname)) { continue; } break; } logger.info("found a available license {}", fname); File target = new File(root, fname); if (target.exists()) { files.add(target);// TODO continue; } FileOutputStream fos = new FileOutputStream(target); IOUtils.copy(zip, fos); IOUtils.closeQuietly(fos); files.add(target); } } catch (Exception e) { logger.error(e.getMessage()); } } return files; } }); } catch (Exception e) { logger.error(e.getMessage(), e); } return null; }
From source file:m3.classe.M3ClassLoader.java
private ZipEntry findZipEntry(String name, ZipInputStream zis) throws MAKException { try {/*ww w. jav a2 s. c o m*/ ZipEntry entry = null; String tmp = name.replace('.', '/') + "."; String match1 = tmp + "class"; String match2 = tmp + "properties"; while ((entry = zis.getNextEntry()) != null) { if ((entry.getName().equals(match1)) || (entry.getName().equals(match2))) { return entry; } } return null; } catch (IOException e) { throw new MAKException("Failed to find entry " + name, e); } }
From source file:com.mcleodmoores.mvn.natives.UnpackDependenciesMojo.java
private void unpack(final Artifact artifact, final Map<String, Set<Artifact>> names, final File targetDir) throws MojoFailureException { getLog().info("Unpacking " + ArtifactUtils.key(artifact)); final IOExceptionHandler errorLog = new MojoLoggingErrorCallback(this); check(artifact, (new IOCallback<InputStream, Boolean>(open(artifact)) { @Override/* w ww. j a v a 2s . co m*/ protected Boolean apply(final InputStream input) throws IOException { final byte[] buffer = new byte[4096]; final ZipInputStream zip = new ZipInputStream(new BufferedInputStream(input)); ZipEntry entry; while ((entry = zip.getNextEntry()) != null) { final String dest = createUniqueName(artifact, entry.getName(), names.get(entry.getName())); getLog().debug("Writing " + entry.getName() + " as " + dest); File targetFile = targetDir; for (final String component : dest.split("/")) { targetFile.mkdir(); targetFile = new File(targetFile, component); } targetFile.getParentFile().mkdirs(); if ((new IOCallback<OutputStream, Boolean>(getOutputStreams().open(targetFile)) { @Override protected Boolean apply(final OutputStream output) throws IOException { int bytes; while ((bytes = zip.read(buffer, 0, buffer.length)) > 0) { output.write(buffer, 0, bytes); } output.close(); return Boolean.TRUE; } }).call(errorLog) != Boolean.TRUE) { return Boolean.FALSE; } } return Boolean.TRUE; } }).call(errorLog)); }