List of usage examples for org.apache.commons.compress.archivers.zip ZipEncodingHelper getZipEncoding
static ZipEncoding getZipEncoding(String name)
From source file:divconq.ctp.stream.UntarStream.java
public UntarStream() { this.encoding = ZipEncodingHelper.getZipEncoding("UTF-8"); }
From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java
/** * Adds a new entry to the archive, takes care of duplicates as well. * @param in the stream to read data for the entry from. * @param zOut the stream to write to. * @param vPath the name this entry shall have in the archive. * @param lastModified last modification time for the entry. * @param fromArchive the original archive we are copying this * @param symlinkDestination/*from ww w . ja v a 2 s. c om*/ */ @SuppressWarnings({ "JavaDoc" }) protected void zipFile(InputStreamSupplier in, ConcurrentJarCreator zOut, String vPath, long lastModified, File fromArchive, int mode, String symlinkDestination) throws IOException, ArchiverException { getLogger().debug("adding entry " + vPath); entries.put(vPath, vPath); if (!skipWriting) { ZipArchiveEntry ze = new ZipArchiveEntry(vPath); setTime(ze, lastModified); ze.setMethod(doCompress ? ZipArchiveEntry.DEFLATED : ZipArchiveEntry.STORED); ze.setUnixMode(UnixStat.FILE_FLAG | mode); InputStream payload; if (ze.isUnixSymlink()) { ZipEncoding enc = ZipEncodingHelper.getZipEncoding(getEncoding()); final byte[] bytes = enc.encode(symlinkDestination).array(); payload = new ByteArrayInputStream(bytes); zOut.addArchiveEntry(ze, createInputStreamSupplier(payload)); } else { zOut.addArchiveEntry(ze, wrappedRecompressor(ze, in)); } } }
From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java
protected void zipDir(PlexusIoResource dir, ConcurrentJarCreator zOut, String vPath, int mode, String encodingToUse) throws IOException { if (addedDirs.update(vPath)) { return;/*from w ww.jav a 2s . c o m*/ } getLogger().debug("adding directory " + vPath); if (!skipWriting) { final boolean isSymlink = dir instanceof SymlinkDestinationSupplier; if (isSymlink && vPath.endsWith(File.separator)) { vPath = vPath.substring(0, vPath.length() - 1); } ZipArchiveEntry ze = new ZipArchiveEntry(vPath); /* * ZipOutputStream.putNextEntry expects the ZipEntry to * know its size and the CRC sum before you start writing * the data when using STORED mode - unless it is seekable. * * This forces us to process the data twice. */ if (isSymlink) { mode = UnixStat.LINK_FLAG | mode; } if (dir != null && dir.isExisting()) { setTime(ze, dir.getLastModified()); } else { // ZIPs store time with a granularity of 2 seconds, round up setTime(ze, System.currentTimeMillis()); } if (!isSymlink) { ze.setSize(0); ze.setMethod(ZipArchiveEntry.STORED); // This is faintly ridiculous: ze.setCrc(EMPTY_CRC); } ze.setUnixMode(mode); if (!isSymlink) { zOut.addArchiveEntry(ze, createInputStreamSupplier(new ByteArrayInputStream("".getBytes()))); } else { String symlinkDestination = ((SymlinkDestinationSupplier) dir).getSymlinkDestination(); ZipEncoding enc = ZipEncodingHelper.getZipEncoding(encodingToUse); final byte[] bytes = enc.encode(symlinkDestination).array(); ze.setMethod(ZipArchiveEntry.DEFLATED); zOut.addArchiveEntry(ze, createInputStreamSupplier(new ByteArrayInputStream(bytes))); } } }