List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry getSize
public long getSize()
From source file:at.spardat.xma.xdelta.JarDelta.java
/** * Test if the content of two byte arrays is completly identical. * * @param sourceEntry the source entry/* w ww . j av a 2 s .co m*/ * @param targetEntry the target entry * @return true if source and target contain the same bytes. */ public boolean equal(ZipArchiveEntry sourceEntry, ZipArchiveEntry targetEntry) { return (sourceEntry.getSize() == targetEntry.getSize()) && (sourceEntry.getCrc() == targetEntry.getCrc()); }
From source file:net.sf.regain.crawler.preparator.ZipPreparator.java
/** * Prepares the document for indexing//from w ww . j a v a2s. co m * * @param rawDocument the document * @throws RegainException if preparation goes wrong */ @Override public void prepare(RawDocument rawDocument) throws RegainException { ArchiveInputStream ain = null; ZipInputStream zipInputStream = new ZipInputStream(rawDocument.getContentAsStream()); PreparatorFactory preparatorFactory = new PreparatorFactory(new DummyCrawlerConfig()); try { ain = new ArchiveStreamFactory().createArchiveInputStream("zip", rawDocument.getContentAsStream()); ZipArchiveEntry entry; while ((entry = (ZipArchiveEntry) ain.getNextEntry()) != null) { String s = String.format("Entry: %s len %d added %TD", entry.getName(), entry.getSize(), new Date(entry.getTime())); System.out.println(s); Preparator preparator = null; ByteArrayOutputStream byteArrayOutputStream = null; RawDocument rawZipDocument = new RawDocument(null, null, null, null); rawZipDocument.setUrl(new File(entry.getName()).toURI().toString()); try { byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(zipInputStream, byteArrayOutputStream); rawZipDocument.setContent(byteArrayOutputStream.toByteArray()); preparator = preparatorFactory.get(rawZipDocument); } finally { IOUtils.closeQuietly(byteArrayOutputStream); } if (preparator != null) { preparator.prepare(rawZipDocument); // concatenates contents setCleanedContent(new StringBuilder().append(getCleanedContent()).append("\n") .append(preparator.getCleanedContent()).toString()); setTitle(getTitle() + " " + preparator.getTitle()); setSummary(getSummary() + " " + preparator.getSummary()); setCleanedMetaData(getCleanedMetaData() + " " + preparator.getCleanedMetaData()); setHeadlines(getHeadlines() + " " + preparator.getHeadlines()); preparator.cleanUp(); } } } catch (IOException | ArchiveException e) { e.printStackTrace(); } finally { //IOUtils.closeQuietly(zipInputStream); IOUtils.closeQuietly(ain); } }
From source file:io.selendroid.builder.SelendroidServerBuilderTest.java
@Test public void testShouldBeAbleToCreateCustomizedAndroidApplicationXML() throws Exception { SelendroidServerBuilder builder = getDefaultBuilder(); builder.init(new DefaultAndroidApp(new File(APK_FILE))); builder.cleanUpPrebuildServer();/*from w ww . j a v a 2 s. c om*/ File file = builder.createAndAddCustomizedAndroidManifestToSelendroidServer(); ZipFile zipFile = new ZipFile(file); ZipArchiveEntry entry = zipFile.getEntry("AndroidManifest.xml"); Assert.assertEquals(entry.getName(), "AndroidManifest.xml"); Assert.assertTrue("Expecting non empty AndroidManifest.xml file", entry.getSize() > 700); // Verify that apk is not yet signed CommandLine cmd = new CommandLine(AndroidSdk.aapt()); cmd.addArgument("list", false); cmd.addArgument(builder.getSelendroidServer().getAbsolutePath(), false); String output = ShellCommand.exec(cmd); assertResultDoesNotContainFile(output, "META-INF/CERT.RSA"); assertResultDoesNotContainFile(output, "META-INF/CERT.SF"); }
From source file:com.haulmont.cuba.core.app.FoldersServiceBean.java
protected ArchiveEntry newStoredEntry(String name, byte[] data) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(name); zipEntry.setSize(data.length);/* ww w. j a v a 2 s . c o m*/ zipEntry.setCompressedSize(zipEntry.getSize()); CRC32 crc32 = new CRC32(); crc32.update(data); zipEntry.setCrc(crc32.getValue()); return zipEntry; }
From source file:de.flapdoodle.embedmongo.extract.ZipExtractor.java
@Override public void extract(RuntimeConfig runtime, File source, File destination, Pattern file) throws IOException { IProgressListener progressListener = runtime.getProgressListener(); String progressLabel = "Extract " + source; progressListener.start(progressLabel); FileInputStream fin = new FileInputStream(source); BufferedInputStream in = new BufferedInputStream(fin); ZipArchiveInputStream zipIn = new ZipArchiveInputStream(in); try {/*from w w w . j a va2 s . co m*/ ZipArchiveEntry entry; while ((entry = zipIn.getNextZipEntry()) != null) { if (file.matcher(entry.getName()).matches()) { // System.out.println("File: " + entry.getName()); if (zipIn.canReadEntryData(entry)) { // System.out.println("Can Read: " + entry.getName()); long size = entry.getSize(); Files.write(zipIn, size, destination); destination.setExecutable(true); // System.out.println("DONE"); progressListener.done(progressLabel); } break; } else { // System.out.println("SKIP File: " + entry.getName()); } } } finally { zipIn.close(); } }
From source file:at.spardat.xma.xdelta.JarDelta.java
/** * Find best source.//from ww w .j a v a2 s. c o m * * @param source the source * @param target the target * @param targetEntry the target entry * @return the zip archive entry * @throws IOException Signals that an I/O exception has occurred. */ public ZipArchiveEntry findBestSource(ZipFile source, ZipFile target, ZipArchiveEntry targetEntry) throws IOException { ArrayList<ZipArchiveEntry> ret = new ArrayList<>(); for (ZipArchiveEntry next : source.getEntries(targetEntry.getName())) { if (next.getCrc() == targetEntry.getCrc()) return next; ret.add(next); } if (ret.size() == 0) return null; if (ret.size() == 1 || targetEntry.isDirectory()) return ret.get(0); //More than one and no matching crc --- need to calculate xdeltas and pick the shortest ZipArchiveEntry retEntry = null; for (ZipArchiveEntry sourceEntry : ret) { try (ByteArrayOutputStream outbytes = new ByteArrayOutputStream()) { Delta d = new Delta(); DiffWriter diffWriter = new GDiffWriter(new DataOutputStream(outbytes)); int sourceSize = (int) sourceEntry.getSize(); byte[] sourceBytes = new byte[sourceSize]; try (InputStream sourceStream = source.getInputStream(sourceEntry)) { for (int erg = sourceStream.read(sourceBytes); erg < sourceBytes.length; erg += sourceStream .read(sourceBytes, erg, sourceBytes.length - erg)) ; } d.compute(sourceBytes, target.getInputStream(targetEntry), diffWriter); byte[] nextDiff = outbytes.toByteArray(); if (calculatedDelta == null || calculatedDelta.length > nextDiff.length) { retEntry = sourceEntry; calculatedDelta = nextDiff; } } } return retEntry; }
From source file:at.spardat.xma.xdelta.test.JarDeltaJarPatcherTest.java
/** * Converts the given zip entry to a byte array. * * @author S3460/* w w w. jav a 2s .c o m*/ * @param zipfile the zipfile * @param entry the entry * @return the byte[] * @throws Exception the exception */ private byte[] toBytes(ZipFile zipfile, ZipArchiveEntry entry) throws Exception { int entrySize = (int) entry.getSize(); byte[] bytes = new byte[entrySize]; InputStream entryStream = zipfile.getInputStream(entry); for (int erg = entryStream.read(bytes); erg < bytes.length; erg += entryStream.read(bytes, erg, bytes.length - erg)) ; return bytes; }
From source file:com.fujitsu.dc.core.bar.BarFileInstaller.java
/** * bar??./*from www.j a v a2 s .co m*/ * @param zae bar * @param entryName ?? * @param maxBarEntryFileSize ? */ protected void checkBarFileEntrySize(ZipArchiveEntry zae, String entryName, long maxBarEntryFileSize) { // [400]bar?????? if (zae.getSize() > (long) (maxBarEntryFileSize * MB)) { String message = "Bar file entry size too large invalid file [%s: %sB]"; log.info(String.format(message, entryName, String.valueOf(zae.getSize()))); throw DcCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE.params(entryName, String.valueOf(zae.getSize())); } }
From source file:io.personium.core.bar.BarFileInstaller.java
/** * bar??./*from w w w .j a va2 s . c o m*/ * @param zae bar * @param entryName ?? * @param maxBarEntryFileSize ? */ protected void checkBarFileEntrySize(ZipArchiveEntry zae, String entryName, long maxBarEntryFileSize) { // [400]bar?????? if (zae.getSize() > (long) (maxBarEntryFileSize * MB)) { String message = "Bar file entry size too large invalid file [%s: %sB]"; log.info(String.format(message, entryName, String.valueOf(zae.getSize()))); throw PersoniumCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE.params(entryName, String.valueOf(zae.getSize())); } }
From source file:com.naryx.tagfusion.expression.function.file.ZipList.java
private cfQueryResultData performZiplist(cfSession session, File zipfile, String charset) throws IOException { ZipFile zFile = null;//from w w w.j a v a 2 s .c om try { cfQueryResultData filesQuery = new cfQueryResultData(new String[] { "name", "type", "compressedsize", "size", "compressedpercent", "datelastmodified", "comment" }, "CFZIP"); zFile = new ZipFile(zipfile, charset); List<Map<String, cfData>> allResultRows = new ArrayList<Map<String, cfData>>(); Map<String, cfData> resultRow; Enumeration<? extends ZipArchiveEntry> files = zFile.getEntries(); ZipArchiveEntry nextEntry = null; long size; double compressed; while (files.hasMoreElements()) { nextEntry = (ZipArchiveEntry) files.nextElement(); resultRow = new FastMap<String, cfData>(8); resultRow.put("name", new cfStringData(nextEntry.getName())); resultRow.put("comment", new cfStringData(nextEntry.getComment())); resultRow.put("datelastmodified", new cfDateData(nextEntry.getTime())); if (nextEntry.isDirectory()) { resultRow.put("compressedsize", new cfNumberData(0)); resultRow.put("size", new cfNumberData(0)); resultRow.put("type", new cfStringData("Dir")); resultRow.put("compressedpercent", new cfNumberData(0)); } else { size = nextEntry.getSize(); resultRow.put("compressedsize", new cfStringData(String.valueOf(nextEntry.getCompressedSize()))); resultRow.put("size", new cfStringData(String.valueOf(size))); resultRow.put("type", new cfStringData("File")); if (size != 0) { compressed = ((float) nextEntry.getCompressedSize() / (float) size); resultRow.put("compressedpercent", new cfStringData(String.valueOf(100 - (int) (compressed * 100)))); } else { resultRow.put("compressedpercent", new cfStringData("0")); } } allResultRows.add(resultRow); } filesQuery.populateQuery(allResultRows); return filesQuery; } finally { try { zFile.close(); } catch (IOException ignored) { } } }