List of usage examples for java.util.jar JarFile getInputStream
public synchronized InputStream getInputStream(ZipEntry ze) throws IOException
From source file:com.liferay.ide.server.util.ServerUtil.java
public static Properties getAllCategories(IPath portalDir) { Properties retval = null;//from w w w. j a va2s. c om File implJar = portalDir.append("WEB-INF/lib/portal-impl.jar").toFile(); //$NON-NLS-1$ if (implJar.exists()) { try { JarFile jar = new JarFile(implJar); Properties categories = new Properties(); Properties props = new Properties(); props.load(jar.getInputStream(jar.getEntry("content/Language.properties"))); //$NON-NLS-1$ Enumeration<?> names = props.propertyNames(); while (names.hasMoreElements()) { String name = names.nextElement().toString(); if (name.startsWith("category.")) //$NON-NLS-1$ { categories.put(name, props.getProperty(name)); } } retval = categories; jar.close(); } catch (IOException e) { LiferayServerCore.logError(e); } } return retval; }
From source file:org.colombbus.tangara.Main.java
public static void copyFilesInTempDirectory() { try {/*from ww w .ja v a 2s. co m*/ // Creation of a temp directory tempDirectory = FileUtils.createTempDirectory(); Configuration conf = Configuration.instance(); StringTokenizer resources = new StringTokenizer(conf.getProperty("program.resources"), ","); String resource = null; JarFile jarFile = new JarFile(conf.getTangaraPath()); while (resources.hasMoreTokens()) { resource = resources.nextToken(); ZipEntry entry = jarFile.getEntry(RESOURCES_DIRECTORY + resource); if (entry == null) { jarFile.close(); throw new Exception("Resource '" + resource + "' not found"); } BufferedInputStream input = new BufferedInputStream(jarFile.getInputStream(entry)); File destinationFile = new File(tempDirectory, resource); destinationFile.createNewFile(); FileUtils.copyFile(input, destinationFile); } } catch (Exception e) { LOG.error("error while copying program files: ", e); } }
From source file:org.wso2.carbon.integration.common.utils.FileManager.java
public static void copyJarFile(File sourceFile, String destinationDirectory) throws IOException { File destinationFileDirectory = new File(destinationDirectory); JarFile jarFile = new JarFile(sourceFile); String fileName = jarFile.getName(); String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator)); File destinationFile = new File(destinationFileDirectory, fileNameLastPart); JarOutputStream jarOutputStream = null; try {//from w w w. j a v a 2 s . c om jarOutputStream = new JarOutputStream(new FileOutputStream(destinationFile)); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); InputStream inputStream = jarFile.getInputStream(jarEntry); //jarOutputStream.putNextEntry(jarEntry); //create a new jarEntry to avoid ZipException: invalid jarEntry compressed size jarOutputStream.putNextEntry(new JarEntry(jarEntry.getName())); byte[] buffer = new byte[4096]; int bytesRead = 0; while ((bytesRead = inputStream.read(buffer)) != -1) { jarOutputStream.write(buffer, 0, bytesRead); } inputStream.close(); jarOutputStream.flush(); jarOutputStream.closeEntry(); } } finally { if (jarOutputStream != null) { try { jarOutputStream.close(); } catch (IOException e) { //ignore } } } }
From source file:com.github.sakserv.minicluster.impl.KnoxLocalCluster.java
public static boolean copyJarResourcesRecursively(final File destDir, final JarURLConnection jarConnection) throws IOException { final JarFile jarFile = jarConnection.getJarFile(); for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) { final JarEntry entry = e.nextElement(); if (entry.getName().startsWith(jarConnection.getEntryName())) { final String filename = StringUtils.removeStart(entry.getName(), // jarConnection.getEntryName()); final File f = new File(destDir, filename); if (!entry.isDirectory()) { final InputStream entryInputStream = jarFile.getInputStream(entry); if (!copyStream(entryInputStream, f)) { return false; }/*w w w.j a v a 2 s . com*/ entryInputStream.close(); } else { if (!ensureDirectoryExists(f)) { throw new IOException("Could not create directory: " + f.getAbsolutePath()); } } } } return true; }
From source file:org.apache.cocoon.portal.pluto.Deploy.java
/** * Deploy the archive//from www. j av a 2 s .c o m * Unpack the archive in the servlet engine context directory */ public static void deployArchive(final String webAppsDir, final String warFile, final String warFileName) throws IOException { System.out.println("Deploying '" + warFileName + "' ..."); final String destination = webAppsDir + warFileName; if (debug) { System.out.println(" unpacking '" + warFile + "' ..."); } final JarFile jarFile = new JarFile(warFile); final Enumeration files = jarFile.entries(); while (files.hasMoreElements()) { JarEntry entry = (JarEntry) files.nextElement(); File file = new File(destination, entry.getName()); File dirF = new File(file.getParent()); dirF.mkdirs(); if (entry.isDirectory()) { file.mkdirs(); } else { byte[] buffer = new byte[1024]; int length = 0; InputStream fis = jarFile.getInputStream(entry); FileOutputStream fos = new FileOutputStream(file); while ((length = fis.read(buffer)) >= 0) { fos.write(buffer, 0, length); } fos.close(); } } if (debug) { System.out.println("Finished!"); } }
From source file:com.ms.commons.test.classloader.IntlTestURLClassPath.java
private static void expandJarTo(JarFile jarFile, String outputPath) throws IOException { List<JarEntry> entries = CollectionUtil.toCollection(ArrayList.class, jarFile.entries()); for (JarEntry entry : entries) { if (entry.isDirectory()) { // ignore directory } else {// www .j a v a 2s.c o m // File efile = new File(outputPath, entry.getName()); efile.getParentFile().mkdirs(); InputStream in = new BufferedInputStream(jarFile.getInputStream(entry)); OutputStream out = new BufferedOutputStream(new FileOutputStream(efile)); IOUtils.copy(in, out); IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } } }
From source file:com.bbxiaoqu.api.util.Utils.java
/** * ???MD5/*from w w w .j a va 2 s . c om*/ */ public static String getFileSignatureMd5(String targetFile) { try { JarFile jarFile = new JarFile(targetFile); // ?RSA JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml"); if (jarEntry != null) { InputStream is = jarFile.getInputStream(jarEntry); byte[] buffer = new byte[8192]; while (is.read(buffer) > 0) { // do nothing } is.close(); Certificate[] certs = jarEntry == null ? null : jarEntry.getCertificates(); if (certs != null && certs.length > 0) { String rsaPublicKey = String.valueOf(certs[0].getPublicKey()); return getMD5(rsaPublicKey); } } } catch (IOException e) { W("occur IOException when get file signature", e); } return ""; }
From source file:com.photon.phresco.service.util.ServerUtil.java
public static InputStream getArtifactPomStream(File artifactFile) throws PhrescoException { String pomFile = null;/* w w w .ja v a2 s . c o m*/ if (getFileExtension(artifactFile.getName()).equals(ServerConstants.JAR_FILE)) { try { JarFile jarfile = new JarFile(artifactFile); for (Enumeration<JarEntry> em = jarfile.entries(); em.hasMoreElements();) { JarEntry jarEntry = em.nextElement(); if (jarEntry.getName().endsWith("pom.xml")) { pomFile = jarEntry.getName(); } } if (pomFile != null) { ZipEntry entry = jarfile.getEntry(pomFile); return jarfile.getInputStream(entry); } } catch (Exception e) { throw new PhrescoException(e); } } return null; }
From source file:org.infoglue.deliver.portal.deploy.Deploy.java
private static int expandArchive(File warFile, File destDir) throws IOException { int numEntries = 0; if (!destDir.exists()) { destDir.mkdirs();//from w ww .j a v a 2 s . co m } JarFile jarFile = new JarFile(warFile); Enumeration files = jarFile.entries(); while (files.hasMoreElements()) { JarEntry entry = (JarEntry) files.nextElement(); String fileName = entry.getName(); File file = new File(destDir, fileName); File dirF = new File(file.getParent()); dirF.mkdirs(); if (entry.isDirectory()) { file.mkdirs(); } else { InputStream fis = jarFile.getInputStream(entry); FileOutputStream fos = new FileOutputStream(file); copyStream(fis, fos); fos.close(); } numEntries++; } return numEntries; }
From source file:ie.deri.unlp.javaservices.topicextraction.topicextractor.gate.TopicExtractorGate.java
/** * //from w w w . j a va 2 s . c om * Extract a directory in a JAR on the classpath to an output folder. * * Note: User's responsibility to ensure that the files are actually in a JAR. * * @param classInJar A class in the JAR file which is on the classpath * @param resourceDirectory Path to resource directory in JAR * @param outputDirectory Directory to write to * @return String containing the path to the outputDirectory * @throws IOException */ private static String extractDirectoryFromClasspathJAR(Class<?> classInJar, String resourceDirectory, String outputDirectory) throws IOException { resourceDirectory = StringUtils.strip(resourceDirectory, "\\/") + File.separator; URL jar = classInJar.getProtectionDomain().getCodeSource().getLocation(); JarFile jarFile = new JarFile(new File(jar.getFile())); byte[] buf = new byte[1024]; Enumeration<JarEntry> jarEntries = jarFile.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); if (jarEntry.isDirectory() || !jarEntry.getName().startsWith(resourceDirectory)) { continue; } String outputFileName = FilenameUtils.concat(outputDirectory, jarEntry.getName()); //Create directories if they don't exist new File(FilenameUtils.getFullPath(outputFileName)).mkdirs(); //Write file FileOutputStream fileOutputStream = new FileOutputStream(outputFileName); int n; InputStream is = jarFile.getInputStream(jarEntry); while ((n = is.read(buf, 0, 1024)) > -1) { fileOutputStream.write(buf, 0, n); } is.close(); fileOutputStream.close(); } jarFile.close(); String fullPath = FilenameUtils.concat(outputDirectory, resourceDirectory); return fullPath; }