List of usage examples for java.util.jar JarEntry getTime
public long getTime()
From source file:JarHelper.java
/** * Given an InputStream on a jar file, unjars the contents into the given * directory./* ww w . j a v a 2 s .c o m*/ */ public void unjar(InputStream in, File destDir) throws IOException { BufferedOutputStream dest = null; JarInputStream jis = new JarInputStream(in); JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { if (entry.isDirectory()) { File dir = new File(destDir, entry.getName()); dir.mkdir(); if (entry.getTime() != -1) dir.setLastModified(entry.getTime()); continue; } int count; byte data[] = new byte[BUFFER_SIZE]; File destFile = new File(destDir, entry.getName()); if (mVerbose) System.out.println("unjarring " + destFile + " from " + entry.getName()); FileOutputStream fos = new FileOutputStream(destFile); dest = new BufferedOutputStream(fos, BUFFER_SIZE); while ((count = jis.read(data, 0, BUFFER_SIZE)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); if (entry.getTime() != -1) destFile.setLastModified(entry.getTime()); } jis.close(); }
From source file:gov.nih.nci.restgen.util.JarHelper.java
/** * Given an InputStream on a jar file, unjars the contents into the given * directory.// w w w.j a va2s.c o m */ public void unjar(InputStream in, File destDir) throws IOException { BufferedOutputStream dest = null; JarInputStream jis = new JarInputStream(in); JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { if (entry.isDirectory()) { File dir = new File(destDir, entry.getName()); dir.mkdir(); if (entry.getTime() != -1) dir.setLastModified(entry.getTime()); continue; } int count; byte data[] = new byte[BUFFER_SIZE]; File destFile = new File(destDir, entry.getName()); if (mVerbose) { //System.out.println("unjarring " + destFile + " from " + entry.getName()); } FileOutputStream fos = new FileOutputStream(destFile); dest = new BufferedOutputStream(fos, BUFFER_SIZE); while ((count = jis.read(data, 0, BUFFER_SIZE)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); if (entry.getTime() != -1) destFile.setLastModified(entry.getTime()); } jis.close(); }
From source file:com.taobao.android.builder.tools.asm.ClazzBasicHandler.java
protected void justCopy(JarFile jarFile, JarOutputStream jos, JarEntry ze, String pathName) { try {/* w ww .j a v a 2 s . c o m*/ InputStream inputStream = jarFile.getInputStream(ze); copyStreamToJar(inputStream, jos, pathName, ze.getTime()); } catch (Exception e) { logger.error("justCopy exception", e); } }
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 a v a2s.com*/ 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()); } }
From source file:com.taobao.android.builder.tools.multidex.FastMultiDexer.java
protected void copyStream(InputStream inputStream, JarOutputStream jos, JarEntry ze, String pathName) { try {/*from w ww . j a va2s . com*/ ZipEntry newEntry = new ZipEntry(pathName); // Make sure there is date and time set. if (ze.getTime() != -1) { newEntry.setTime(ze.getTime()); // 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); } }
From source file:com.taobao.android.builder.tools.asm.MethodReplacer.java
@Override protected void handleClazz(JarFile jarFile, JarOutputStream jos, JarEntry ze, String pathName) { try {//from w w w .j a v a2s . c om InputStream jarFileInputStream = jarFile.getInputStream(ze); ClassReader classReader = new ClassReader(jarFileInputStream); ClassWriter classWriter = new ClassWriter(0); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(jar.getAbsolutePath()).append(".").append(pathName); classReader.accept(new MethodReplaceClazzVisitor(Opcodes.ASM4, classWriter, methodStore, stringBuilder), ClassReader.EXPAND_FRAMES); ByteArrayInputStream inputStream = new ByteArrayInputStream(classWriter.toByteArray()); copyStreamToJar(inputStream, jos, pathName, ze.getTime()); IOUtils.closeQuietly(inputStream); } catch (Throwable e) { System.err.println("[MethodReplacer] rewrite error > " + pathName); justCopy(jarFile, jos, ze, pathName); } }
From source file:com.migratebird.script.repository.impl.ArchiveScriptLocation.java
protected SortedSet<Script> loadScriptsFromJar(final JarFile jarFile, String subPath) { SortedSet<Script> scripts = new TreeSet<Script>(); for (Enumeration<JarEntry> jarEntries = jarFile.entries(); jarEntries.hasMoreElements();) { final JarEntry jarEntry = jarEntries.nextElement(); String fileName = jarEntry.getName(); if (LOCATION_PROPERTIES_FILENAME.equals(fileName) || !isScriptFileName(fileName)) { continue; }// w w w .ja va 2s .com String relativeScriptName = jarEntry.getName(); if (subPath != null) { if (!fileName.startsWith(subPath)) { continue; } relativeScriptName = relativeScriptName.substring(subPath.length()); } ScriptContentHandle scriptContentHandle = new ScriptContentHandle(scriptEncoding, ignoreCarriageReturnsWhenCalculatingCheckSum) { @Override protected InputStream getScriptInputStream() { try { return jarFile.getInputStream(jarEntry); } catch (IOException e) { throw new MigrateBirdException("Error while reading jar entry " + jarEntry, e); } } }; Long fileLastModifiedAt = jarEntry.getTime(); Script script = scriptFactory.createScriptWithContent(relativeScriptName, fileLastModifiedAt, scriptContentHandle); scripts.add(script); } return scripts; }
From source file:org.apache.maven.shared.jar.identification.exposers.TimestampExposer.java
public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) { List entries = jarAnalyzer.getEntries(); SimpleDateFormat tsformat = new SimpleDateFormat("yyyyMMdd", Locale.US); //$NON-NLS-1$ Bag timestamps = new HashBag(); Iterator it = entries.iterator(); while (it.hasNext()) { JarEntry entry = (JarEntry) it.next(); long time = entry.getTime(); String timestamp = tsformat.format(new Date(time)); timestamps.add(timestamp);//from www . j av a 2s. com } it = timestamps.iterator(); String ts = ""; int tsmax = 0; while (it.hasNext()) { String timestamp = (String) it.next(); int count = timestamps.getCount(timestamp); if (count > tsmax) { ts = timestamp; tsmax = count; } } if (StringUtils.isNotEmpty(ts)) { identification.addVersion(ts); } }
From source file:org.apache.pluto.util.assemble.io.JarStreamingAssembly.java
private static JarEntry smartClone(JarEntry originalJarEntry) { final JarEntry newJarEntry = new JarEntry(originalJarEntry.getName()); newJarEntry.setComment(originalJarEntry.getComment()); newJarEntry.setExtra(originalJarEntry.getExtra()); newJarEntry.setMethod(originalJarEntry.getMethod()); newJarEntry.setTime(originalJarEntry.getTime()); //Must set size and CRC for STORED entries if (newJarEntry.getMethod() == ZipEntry.STORED) { newJarEntry.setSize(originalJarEntry.getSize()); newJarEntry.setCrc(originalJarEntry.getCrc()); }//from w ww . jav a 2 s . c o m return newJarEntry; }
From source file:org.apache.sling.maven.bundlesupport.AbstractBundleDeployMojo.java
/** * Change the version in jar/* w w w .j av a 2s. c o m*/ * * @param newVersion * @param file * @return * @throws MojoExecutionException */ protected File changeVersion(File file, String oldVersion, String newVersion) throws MojoExecutionException { String fileName = file.getName(); int pos = fileName.indexOf(oldVersion); fileName = fileName.substring(0, pos) + newVersion + fileName.substring(pos + oldVersion.length()); JarInputStream jis = null; JarOutputStream jos; OutputStream out = null; JarFile sourceJar = null; try { // now create a temporary file and update the version sourceJar = new JarFile(file); final Manifest manifest = sourceJar.getManifest(); manifest.getMainAttributes().putValue("Bundle-Version", newVersion); jis = new JarInputStream(new FileInputStream(file)); final File destJar = new File(file.getParentFile(), fileName); out = new FileOutputStream(destJar); jos = new JarOutputStream(out, manifest); jos.setMethod(JarOutputStream.DEFLATED); jos.setLevel(Deflater.BEST_COMPRESSION); JarEntry entryIn = jis.getNextJarEntry(); while (entryIn != null) { JarEntry entryOut = new JarEntry(entryIn.getName()); entryOut.setTime(entryIn.getTime()); entryOut.setComment(entryIn.getComment()); jos.putNextEntry(entryOut); if (!entryIn.isDirectory()) { IOUtils.copy(jis, jos); } jos.closeEntry(); jis.closeEntry(); entryIn = jis.getNextJarEntry(); } // close the JAR file now to force writing jos.close(); return destJar; } catch (IOException ioe) { throw new MojoExecutionException("Unable to update version in jar file.", ioe); } finally { if (sourceJar != null) { try { sourceJar.close(); } catch (IOException ex) { // close } } IOUtils.closeQuietly(jis); IOUtils.closeQuietly(out); } }