List of usage examples for java.util.zip ZipEntry setTime
public void setTime(long time)
From source file:org.phpmaven.phpnar.PackageMojo.java
private void zipPhpizeBat(ZipOutputStream zos, File file, String string) throws IOException { if (file.exists()) { zip(zos, file, string);// w w w. ja v a 2s.c o m } else { // use a default file content taken from 5.3.10 for early 5.3.x versions (they did not contain the phpize windows variants but they should be compatible) final StringWriter writer = new StringWriter(); IOUtils.copy(PackageMojo.class.getResourceAsStream("php5.3.x/phpize.bat"), writer, "UTF-8"); String contents = writer.toString(); final ZipEntry entry = new ZipEntry(string.substring(1)); entry.setTime(file.lastModified()); zos.putNextEntry(entry); zos.write(contents.getBytes()); zos.closeEntry(); } }
From source file:org.phpmaven.phpnar.PackageMojo.java
private void zipMakefilePhpize(ZipOutputStream zos, File file, String string) throws IOException { if (file.exists()) { zip(zos, file, string);//from w w w .j a v a 2 s . com } else { // use a default file content taken from 5.3.10 for early 5.3.x versions (they did not contain the phpize windows variants but they should be compatible) final StringWriter writer = new StringWriter(); IOUtils.copy(PackageMojo.class.getResourceAsStream("php5.3.x/Makefile.phpize"), writer, "UTF-8"); String contents = writer.toString(); final ZipEntry entry = new ZipEntry(string.substring(1)); entry.setTime(file.lastModified()); zos.putNextEntry(entry); zos.write(contents.getBytes()); zos.closeEntry(); } }
From source file:org.phpmaven.phpnar.PackageMojo.java
private void zipConfigW32PhpizeIn(ZipOutputStream zos, File file, String string) throws IOException { if (file.exists()) { zip(zos, file, string);/*from w w w . j av a 2s .c om*/ } else { // use a default file content taken from 5.3.10 for early 5.3.x versions (they did not contain the phpize windows variants but they should be compatible) final StringWriter writer = new StringWriter(); IOUtils.copy(PackageMojo.class.getResourceAsStream("php5.3.x/config.w32.phpize.in"), writer, "UTF-8"); String contents = writer.toString(); final ZipEntry entry = new ZipEntry(string.substring(1)); entry.setTime(file.lastModified()); zos.putNextEntry(entry); zos.write(contents.getBytes()); zos.closeEntry(); } }
From source file:org.phpmaven.phpnar.PackageMojo.java
private void zipFilterFile(ZipOutputStream target, File file, String pathNameInFile, String filterFrom, String filterTo) throws IOException { if (!file.exists()) return;//www . ja v a2 s.c om final String contents = FileUtils.fileRead(file).replace(filterFrom, filterTo); final ZipEntry entry = new ZipEntry(pathNameInFile.substring(1)); entry.setTime(file.lastModified()); target.putNextEntry(entry); target.write(contents.getBytes()); target.closeEntry(); }
From source file:org.phpmaven.phpnar.PackageMojo.java
private void zipExtDepsJs(ZipOutputStream zos, File file, String string) throws IOException { if (file.exists()) { zip(zos, file, string);/*from w ww .j a v a 2 s .c o m*/ } else { // use a default file content taken from 5.3.10 for early 5.3.x versions (they did not contain the phpize windows variants but they should be compatible) // TODO should be generated from dependencies information final StringWriter writer = new StringWriter(); IOUtils.copy(PackageMojo.class.getResourceAsStream("php5.3.x/ext_deps.js"), writer, "UTF-8"); String contents = writer.toString(); final ZipEntry entry = new ZipEntry(string.substring(1)); entry.setTime(file.lastModified()); zos.putNextEntry(entry); zos.write(contents.getBytes()); zos.closeEntry(); } }
From source file:org.phpmaven.phpnar.PackageMojo.java
private void zipPhpizeJs(ZipOutputStream zos, File file, String string) throws IOException { if (file.exists()) { zip(zos, file, string);//from ww w . j a v a 2 s .com } else { // use a default file content taken from 5.3.10 for early 5.3.x versions (they did not contain the phpize windows variants but they should be compatible) final StringWriter writer = new StringWriter(); IOUtils.copy(PackageMojo.class.getResourceAsStream("php5.3.x/phpize.js"), writer, "UTF-8"); String contents = writer.toString(); contents = contents.replace("${PHP_RELEASE_VERSION}", this.project.getVersion().split("\\.")[2]); final ZipEntry entry = new ZipEntry(string.substring(1)); entry.setTime(file.lastModified()); zos.putNextEntry(entry); zos.write(contents.getBytes()); zos.closeEntry(); } }
From source file:com.veniosg.dir.mvvm.model.storage.operation.CompressOperation.java
/** * Recursively compress a File./* w w w.j av a 2s . co m*/ * * @return How many files where compressed. */ private int compressCore(int notId, ZipOutputStream zipStream, File toCompress, String internalPath, int filesCompressed, final int fileCount, File zipFile) throws IOException { if (internalPath == null) internalPath = ""; showCompressProgressNotification(filesCompressed, fileCount, notId, zipFile, toCompress, context); if (toCompress.isFile()) { byte[] buf = new byte[BUFFER_SIZE]; int len; FileInputStream in = new FileInputStream(toCompress); // Create internal zip file entry. ZipEntry entry; if (internalPath.length() > 0) { entry = new ZipEntry(internalPath + "/" + toCompress.getName()); } else { entry = new ZipEntry(toCompress.getName()); } entry.setTime(toCompress.lastModified()); zipStream.putNextEntry(entry); // Compress while ((len = in.read(buf)) > 0) { zipStream.write(buf, 0, len); } filesCompressed++; zipStream.closeEntry(); in.close(); } else { if (toCompress.list().length == 0) { zipStream.putNextEntry(new ZipEntry(internalPath + "/" + toCompress.getName() + "/")); zipStream.closeEntry(); } else { for (File child : toCompress.listFiles()) { filesCompressed = compressCore(notId, zipStream, child, internalPath + "/" + toCompress.getName(), filesCompressed, fileCount, zipFile); } } } return filesCompressed; }
From source file:org.phpmaven.phpnar.PackageMojo.java
private void add(int relLength, File source, ZipOutputStream target, String prepend) throws IOException { BufferedInputStream in = null; try {/*from w ww. ja v a 2 s .c o m*/ if (source.isDirectory()) { String name = source.getPath().substring(relLength).replace("\\", "/"); if (!name.isEmpty()) { if (!name.endsWith("/")) name += "/"; ZipEntry entry = new ZipEntry(prepend + name); entry.setTime(source.lastModified()); target.putNextEntry(entry); target.closeEntry(); } for (File nestedFile : source.listFiles()) add(relLength, nestedFile, target, prepend); return; } ZipEntry entry = new ZipEntry( prepend.substring(1) + source.getPath().substring(relLength).replace("\\", "/")); entry.setTime(source.lastModified()); target.putNextEntry(entry); in = new BufferedInputStream(new FileInputStream(source)); byte[] buffer = new byte[1024]; while (true) { int count = in.read(buffer); if (count == -1) break; target.write(buffer, 0, count); } target.closeEntry(); } finally { if (in != null) in.close(); } }
From source file:processing.app.tools.Archiver.java
public void buildZip(File dir, String sofar, ZipOutputStream zos) throws IOException { String files[] = dir.list();/* w w w. j a v a 2 s. co m*/ if (files == null) { throw new IOException("Unable to list files from " + dir); } for (int i = 0; i < files.length; i++) { if (files[i].equals(".") || files[i].equals("..")) continue; File sub = new File(dir, files[i]); String nowfar = (sofar == null) ? files[i] : (sofar + "/" + files[i]); if (sub.isDirectory()) { // directories are empty entries and have / at the end ZipEntry entry = new ZipEntry(nowfar + "/"); //System.out.println(entry); zos.putNextEntry(entry); zos.closeEntry(); buildZip(sub, nowfar, zos); } else { ZipEntry entry = new ZipEntry(nowfar); entry.setTime(sub.lastModified()); zos.putNextEntry(entry); zos.write(Base.loadBytesRaw(sub)); zos.closeEntry(); } } }
From source file:com.taobao.android.builder.tools.multidex.mutli.JarRefactor.java
private void copyStream(InputStream inputStream, JarOutputStream jos, JarEntry ze, String pathName) { try {//from w ww . j av a 2 s . c o m ZipEntry newEntry = new ZipEntry(pathName); // Make sure there is date and time set. if (ze.getTime() != -1) { newEntry.setTime(ze.getTime()); newEntry.setCrc(ze.getCrc()); // If found set it into output file. } jos.putNextEntry(newEntry); IOUtils.copy(inputStream, jos); IOUtils.closeQuietly(inputStream); } catch (Exception e) { //throw new GradleException("copy stream exception", e); //e.printStackTrace(); logger.error("copy stream exception >>> " + pathName + " >>>" + e.getMessage()); } }