List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry setSize
public void setSize(long size)
From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java
private static ArchiveEntry newTailArchive(String name, byte[] tail) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(name); zipEntry.setSize(tail.length); zipEntry.setCompressedSize(zipEntry.getSize()); CRC32 crc32 = new CRC32(); crc32.update(tail);// w w w . ja v a 2 s . c o m zipEntry.setCrc(crc32.getValue()); return zipEntry; }
From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java
private static ArchiveEntry newArchive(File file) throws IOException { ZipArchiveEntry zipEntry = new ZipArchiveEntry(file.getName()); zipEntry.setSize(file.length()); zipEntry.setCompressedSize(zipEntry.getSize()); zipEntry.setCrc(FileUtils.checksumCRC32(file)); return zipEntry; }
From source file:com.offbynull.coroutines.instrumenter.testhelpers.TestUtils.java
private static void writeJarEntry(JarArchiveOutputStream jaos, String name, byte[] data) throws IOException { ZipArchiveEntry entry = new JarArchiveEntry(name); entry.setSize(data.length); jaos.putArchiveEntry(entry);//from www.ja v a 2 s. c om jaos.write(data); jaos.closeArchiveEntry(); }
From source file:com.gitblit.utils.CompressionUtils.java
/** * Zips the contents of the tree at the (optionally) specified revision and * the (optionally) specified basepath to the supplied outputstream. * /*from ww w. jav a 2s . c om*/ * @param repository * @param basePath * if unspecified, entire repository is assumed. * @param objectId * if unspecified, HEAD is assumed. * @param os * @return true if repository was successfully zipped to supplied output * stream */ public static boolean zip(Repository repository, String basePath, String objectId, OutputStream os) { RevCommit commit = JGitUtils.getCommit(repository, objectId); if (commit == null) { return false; } boolean success = false; RevWalk rw = new RevWalk(repository); TreeWalk tw = new TreeWalk(repository); try { tw.reset(); tw.addTree(commit.getTree()); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os); zos.setComment("Generated by Gitblit"); if (!StringUtils.isEmpty(basePath)) { PathFilter f = PathFilter.create(basePath); tw.setFilter(f); } tw.setRecursive(true); MutableObjectId id = new MutableObjectId(); ObjectReader reader = tw.getObjectReader(); long modified = commit.getAuthorIdent().getWhen().getTime(); while (tw.next()) { FileMode mode = tw.getFileMode(0); if (mode == FileMode.GITLINK || mode == FileMode.TREE) { continue; } tw.getObjectId(id, 0); ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString()); entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB)); entry.setComment(commit.getName()); entry.setUnixMode(mode.getBits()); entry.setTime(modified); zos.putArchiveEntry(entry); ObjectLoader ldr = repository.open(id); ldr.copyTo(zos); zos.closeArchiveEntry(); } zos.finish(); success = true; } catch (IOException e) { error(e, repository, "{0} failed to zip files from commit {1}", commit.getName()); } finally { tw.release(); rw.dispose(); } return success; }
From source file:at.spardat.xma.xdelta.JarDelta.java
/** * Entry to new name.//from w w w . j a va2 s. c o m * * @param source the source * @param name the name * @return the zip archive entry * @throws ZipException the zip exception */ public static ZipArchiveEntry entryToNewName(ZipArchiveEntry source, String name) throws ZipException { if (source.getName().equals(name)) return new ZipArchiveEntry(source); ZipArchiveEntry ret = new ZipArchiveEntry(name); byte[] extra = source.getExtra(); if (extra != null) { ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ)); } else { ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true))); } ret.setInternalAttributes(source.getInternalAttributes()); ret.setExternalAttributes(source.getExternalAttributes()); ret.setExtraFields(source.getExtraFields(true)); ret.setCrc(source.getCrc()); ret.setMethod(source.getMethod()); ret.setSize(source.getSize()); return ret; }
From source file:edu.jhu.hlt.acute.archivers.zip.ZipArchiver.java
@Override public void addEntry(Archivable arch) throws IOException { final String fn = arch.getFileName(); ZipArchiveEntry entry = new ZipArchiveEntry(fn); byte[] cbytes = arch.getBytes(); entry.setSize(cbytes.length); this.zout.putArchiveEntry(entry); try (ByteArrayInputStream bis = new ByteArrayInputStream(cbytes)) { IOUtils.copy(bis, zout);/*from ww w .j a va 2s. com*/ this.zout.closeArchiveEntry(); } }
From source file:com.streamsets.datacollector.restapi.ZipEdgeArchiveBuilder.java
protected void addArchiveEntry(ArchiveOutputStream archiveOutput, Object fileContent, String pipelineId, String fileName) throws IOException { File pipelineFile = File.createTempFile(pipelineId, fileName); FileOutputStream pipelineOutputStream = new FileOutputStream(pipelineFile); ObjectMapperFactory.get().writeValue(pipelineOutputStream, fileContent); pipelineOutputStream.flush();//from www . j av a 2 s .c o m pipelineOutputStream.close(); ZipArchiveEntry archiveEntry = new ZipArchiveEntry(pipelineFile, DATA_PIPELINES_FOLDER + pipelineId + "/" + fileName); archiveEntry.setSize(pipelineFile.length()); archiveOutput.putArchiveEntry(archiveEntry); IOUtils.copy(new FileInputStream(pipelineFile), archiveOutput); archiveOutput.closeArchiveEntry(); }
From source file:gov.nih.nci.caarray.application.fileaccess.FileAccessUtils.java
/** * This method creates an ArchiveEntry w/o the need of a File required by * ArchiveOutputStream.createArchiveEntry(File inputFile, String entryName). * /*from ww w . jav a2 s .co m*/ * @param aos archive output stream. * @param name name of entry. * @param size size in bytes of the entry. * @return an archive entry that matches the archive stream. */ public ArchiveEntry createArchiveEntry(ArchiveOutputStream aos, String name, long size) { if (aos instanceof TarArchiveOutputStream) { final TarArchiveEntry te = new TarArchiveEntry(name); te.setSize(size); return te; } else if (aos instanceof ZipArchiveOutputStream) { final ZipArchiveEntry ze = new ZipArchiveEntry(name); ze.setSize(size); return ze; } throw new UnsupportedOperationException("unsupported archive " + aos.getClass()); }
From source file:br.com.thiaguten.archive.ZipArchive.java
@Override protected ArchiveEntry createArchiveEntry(String path, long size, byte[] content) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(path); zipEntry.setSize(size); return zipEntry; }
From source file:fr.gael.ccsds.sip.archive.ZipArchiveManager.java
/** * Produces Zip compressed archive./*w ww . j a v a2 s .c o m*/ */ @Override public File copy(final File src, final File zip_file, final String dst) throws Exception { if (zip_file.exists()) { final FileInputStream fis = new FileInputStream(zip_file); final ZipArchiveInputStream zis = new ZipArchiveInputStream(fis); final File tempFile = File.createTempFile("updateZip", "zip"); final FileOutputStream fos = new FileOutputStream(tempFile); final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos); // copy the existing entries ZipArchiveEntry nextEntry; while ((nextEntry = zis.getNextZipEntry()) != null) { zos.putArchiveEntry(nextEntry); IOUtils.copy(zis, zos); zos.closeArchiveEntry(); } // create the new entry final ZipArchiveEntry entry = new ZipArchiveEntry(src, dst); entry.setSize(src.length()); zos.putArchiveEntry(entry); final FileInputStream sfis = new FileInputStream(src); IOUtils.copy(sfis, zos); sfis.close(); zos.closeArchiveEntry(); zos.finish(); zis.close(); fis.close(); zos.close(); // Rename the new file over the old boolean status = zip_file.delete(); File saved_tempFile = tempFile; status = tempFile.renameTo(zip_file); // Copy the new file over the old if the renaming failed if (!status) { final FileInputStream tfis = new FileInputStream(saved_tempFile); final FileOutputStream tfos = new FileOutputStream(zip_file); final byte[] buf = new byte[1024]; int i = 0; while ((i = tfis.read(buf)) != -1) { tfos.write(buf, 0, i); } tfis.close(); tfos.close(); saved_tempFile.delete(); } return zip_file; } else { final FileOutputStream fos = new FileOutputStream(zip_file); final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos); final ZipArchiveEntry entry = new ZipArchiveEntry(src, dst); entry.setSize(src.length()); zos.putArchiveEntry(entry); final FileInputStream sfis = new FileInputStream(src); IOUtils.copy(sfis, zos); sfis.close(); zos.closeArchiveEntry(); zos.finish(); zos.close(); fos.close(); } return zip_file; }