List of usage examples for java.util.zip ZipInputStream getNextEntry
public ZipEntry getNextEntry() throws IOException
From source file:com.ikanow.aleph2.analytics.storm.utils.TestStormControllerUtil_Cache.java
private long getFileModifiedTime(File input_jar) throws IOException { ZipInputStream inputZip = new ZipInputStream(new FileInputStream(input_jar)); ZipEntry e = inputZip.getNextEntry(); long time = e.getLastModifiedTime().toMillis(); inputZip.close();//w ww.j a v a2 s . com return time; }
From source file:com.marklogic.contentpump.CompressedDocumentReader.java
@Override public boolean nextKeyValue() throws IOException, InterruptedException { if (zipIn == null) { hasNext = false;//ww w . j a v a 2s .c om return false; } if (codec == CompressionCodec.ZIP) { ZipEntry zipEntry; ZipInputStream zis = (ZipInputStream) zipIn; while (true) { try { zipEntry = zis.getNextEntry(); if (zipEntry == null) { break; } if (zipEntry.getSize() == 0) { continue; } subId = zipEntry.getName(); String uri = makeURIForZipEntry(file, subId); if (setKey(uri, 0, 0, true)) { return true; } setValue(zipEntry.getSize()); return true; } catch (IllegalArgumentException e) { LOG.warn("Skipped a zip entry in : " + file.toUri() + ", reason: " + e.getMessage()); } } } else if (codec == CompressionCodec.GZIP) { setValue(0); zipIn.close(); zipIn = null; hasNext = false; return true; } else { return false; } if (iterator != null && iterator.hasNext()) { close(); initStream(iterator.next()); return nextKeyValue(); } else { hasNext = false; return false; } }
From source file:be.fedict.eid.dss.document.odf.ODFDSSDocumentService.java
private void checkIntegrity(XMLSignature xmlSignature, byte[] document, byte[] originalDocument) throws IOException { if (null != originalDocument) { throw new IllegalArgumentException("cannot perform original document verifications"); }// w ww. java 2 s . c o m Set<String> dsReferenceUris = new HashSet<String>(); SignedInfo signedInfo = xmlSignature.getSignedInfo(); @SuppressWarnings("unchecked") List<Reference> references = signedInfo.getReferences(); for (Reference reference : references) { String referenceUri = reference.getURI(); dsReferenceUris.add(referenceUri); } ZipInputStream odfZipInputStream = new ZipInputStream(new ByteArrayInputStream(document)); ZipEntry zipEntry; while (null != (zipEntry = odfZipInputStream.getNextEntry())) { if (false == ODFUtil.isToBeSigned(zipEntry)) { continue; } String uri = zipEntry.getName().replaceAll(" ", "%20"); if (false == dsReferenceUris.contains(uri)) { LOG.warn("no ds:Reference for ODF entry: " + zipEntry.getName()); throw new RuntimeException("no ds:Reference for ODF entry: " + zipEntry.getName()); } } }
From source file:com.joliciel.lefff.LefffMemoryLoader.java
public LefffMemoryBase deserializeMemoryBase(ZipInputStream zis) { LefffMemoryBase memoryBase = null;//ww w. ja v a 2 s . c om MONITOR.startTask("deserializeMemoryBase"); try { ZipEntry zipEntry; if ((zipEntry = zis.getNextEntry()) != null) { LOG.debug("Scanning zip entry " + zipEntry.getName()); ObjectInputStream in = new ObjectInputStream(zis); memoryBase = (LefffMemoryBase) in.readObject(); zis.closeEntry(); in.close(); } else { throw new RuntimeException("No zip entry in input stream"); } } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } finally { MONITOR.endTask("deserializeMemoryBase"); } Map<PosTagSet, LefffPosTagMapper> posTagMappers = memoryBase.getPosTagMappers(); PosTagSet posTagSet = posTagMappers.keySet().iterator().next(); memoryBase.setPosTagSet(posTagSet); return memoryBase; }
From source file:com.espringtran.compressor4j.processor.LzmaProcessor.java
/** * Read from compressed file/*from ww w . ja va2 s . com*/ * * @param srcPath * path of compressed file * @param fileCompressor * FileCompressor object * @throws Exception */ @Override public void read(String srcPath, FileCompressor fileCompressor) throws Exception { long t1 = System.currentTimeMillis(); byte[] data = FileUtil.convertFileToByte(srcPath); ByteArrayInputStream bais = new ByteArrayInputStream(data); LZMACompressorInputStream cis = new LZMACompressorInputStream(bais); ZipInputStream zis = new ZipInputStream(cis); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { byte[] buffer = new byte[1024]; int readByte; ZipEntry entry = zis.getNextEntry(); while (entry != null) { long t2 = System.currentTimeMillis(); baos = new ByteArrayOutputStream(); readByte = zis.read(buffer); while (readByte != -1) { baos.write(buffer, 0, readByte); readByte = zis.read(buffer); } zis.closeEntry(); BinaryFile binaryFile = new BinaryFile(entry.getName(), baos.toByteArray()); fileCompressor.addBinaryFile(binaryFile); LogUtil.createAddFileLog(fileCompressor, binaryFile, t2, System.currentTimeMillis()); entry = zis.getNextEntry(); } } catch (Exception e) { FileCompressor.LOGGER.error("Error on get compressor file", e); } finally { baos.close(); zis.close(); cis.close(); bais.close(); } LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1, System.currentTimeMillis()); }
From source file:com.marklogic.contentpump.CompressedDelimitedTextReader.java
private boolean nextKeyValueInZip() throws IOException, InterruptedException { ByteArrayOutputStream baos;//from www .ja v a2s. c om ZipInputStream zis = (ZipInputStream) zipIn; while (true) { currZipEntry = zis.getNextEntry(); if (currZipEntry == null) { break; } if (LOG.isDebugEnabled()) { LOG.debug("ZipEntry: " + currZipEntry.getName()); } if (currZipEntry.getSize() == 0) { continue; } subId = currZipEntry.getName(); long size = currZipEntry.getSize(); if (size == -1) { baos = new ByteArrayOutputStream(); } else { baos = new ByteArrayOutputStream((int) size); } int nb; while ((nb = zis.read(buf, 0, buf.length)) != -1) { baos.write(buf, 0, nb); } if (encoding == null) { instream = new InputStreamReader(new ByteArrayInputStream(baos.toByteArray())); } else { instream = new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()), encoding); } baos.close(); parser = new CSVParser(instream, CSVParserFormatter.getFormat(delimiter, encapsulator, true, true)); parserIterator = parser.iterator(); // clear metadata fields = null; if (super.nextKeyValue()) { // current delim txt has next return true; } // continue read next zip entry if any } // end of zip if (iterator != null && iterator.hasNext()) { close(); initStream(iterator.next()); return nextKeyValueInZip(); } else { hasNext = false; return false; } }
From source file:com.intuit.tank.standalone.agent.StandaloneAgentStartup.java
public void startTest(final StandaloneAgentRequest request) { Thread t = new Thread(new Runnable() { public void run() { try { currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.DELEGATING); sendAvailability();/*from w w w . ja v a 2 s.c o m*/ LOG.info("Starting up: ControllerBaseUrl=" + controllerBase); URL url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SETTINGS); LOG.info("Starting up: making call to tank service url to get settings.xml " + url.toExternalForm()); InputStream settingsStream = url.openStream(); try { String settings = IOUtils.toString(settingsStream); FileUtils.writeStringToFile(new File("settings.xml"), settings); LOG.info("got settings file..."); } finally { IOUtils.closeQuietly(settingsStream); } url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SUPPORT); LOG.info("Making call to tank service url to get support files " + url.toExternalForm()); ZipInputStream zip = new ZipInputStream(url.openStream()); try { ZipEntry entry = zip.getNextEntry(); while (entry != null) { String name = entry.getName(); LOG.info("Got file from controller: " + name); File f = new File(name); FileOutputStream fout = FileUtils.openOutputStream(f); try { IOUtils.copy(zip, fout); } finally { IOUtils.closeQuietly(fout); } entry = zip.getNextEntry(); } } finally { IOUtils.closeQuietly(zip); } // now start the harness String cmd = API_HARNESS_COMMAND + " -http=" + controllerBase + " -jobId=" + request.getJobId() + " -stopBehavior=" + request.getStopBehavior(); LOG.info("Starting apiharness with command: " + cmd); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.RUNNING_JOB); sendAvailability(); Process exec = Runtime.getRuntime().exec(cmd); exec.waitFor(); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.AVAILABLE); sendAvailability(); // } catch (Exception e) { LOG.error("Error in AgentStartup " + e, e); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.AVAILABLE); sendAvailability(); } } }); t.start(); }
From source file:com.obnsoft.ptcm3.MyApplication.java
private boolean downloadZipFile(String url, String target, String fileName, boolean force) { if (!force && getFileStreamPath(fileName).exists()) { return true; }/*from w w w. j av a 2 s . c o m*/ try { HttpClient httpclient = new DefaultHttpClient(); HttpResponse httpResponse = httpclient.execute(new HttpGet(url)); ZipInputStream zin = new ZipInputStream(httpResponse.getEntity().getContent()); for (ZipEntry entry = zin.getNextEntry(); entry != null; entry = zin.getNextEntry()) { if (target.equals(entry.getName())) { OutputStream out = openFileOutput(fileName, MODE_PRIVATE); byte[] buffer = new byte[1024 * 1024]; int length; while ((length = zin.read(buffer)) >= 0) { out.write(buffer, 0, length); } out.close(); break; } } zin.close(); } catch (Exception e) { e.printStackTrace(); getFileStreamPath(fileName).delete(); return false; } return true; }
From source file:org.ktunaxa.referral.server.mvc.UploadGeometryController.java
private URL unzipShape(byte[] fileContent) throws IOException { String tempDir = System.getProperty("java.io.tmpdir"); URL url = null;// ww w . jav a2 s . c om ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(fileContent)); try { ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { log.info("Extracting: " + entry); String name = tempDir + "/" + entry.getName(); tempFiles.add(name); if (name.endsWith(".shp")) { url = new URL("file://" + name); } int count; byte[] data = new byte[BUFFER]; // write the files to the disk deleteFileIfExists(name); FileOutputStream fos = new FileOutputStream(name); BufferedOutputStream destination = new BufferedOutputStream(fos, BUFFER); try { while ((count = zin.read(data, 0, BUFFER)) != -1) { destination.write(data, 0, count); } destination.flush(); } finally { destination.close(); } } } finally { zin.close(); } if (url == null) { throw new IllegalArgumentException("Missing .shp file"); } return url; }
From source file:ZipTest.java
/** * Loads a file from the ZIP archive into the text area * @param name the name of the file in the archive *//* w w w .j a v a 2 s . c o m*/ public void loadZipFile(final String name) { fileCombo.setEnabled(false); fileText.setText(""); new SwingWorker<Void, Void>() { protected Void doInBackground() throws Exception { try { ZipInputStream zin = new ZipInputStream(new FileInputStream(zipname)); ZipEntry entry; // find entry with matching name in archive while ((entry = zin.getNextEntry()) != null) { if (entry.getName().equals(name)) { // read entry into text area Scanner in = new Scanner(zin); while (in.hasNextLine()) { fileText.append(in.nextLine()); fileText.append("\n"); } } zin.closeEntry(); } zin.close(); } catch (IOException e) { e.printStackTrace(); } return null; } protected void done() { fileCombo.setEnabled(true); } }.execute(); }