List of usage examples for java.util.jar JarFile JarFile
public JarFile(File file) throws IOException
From source file:Main.java
static boolean isTheUpdateForMe(File path) { JarFile jar;/* ww w. j av a 2 s . co m*/ try { jar = new JarFile(path); } catch (IOException e) { // TODO Auto-generated catch block return false; } ZipEntry entry = jar.getEntry("system/build.prop"); final String myDevice = "ro.product.device=" + Build.DEVICE; boolean finded = false; if (entry != null) { try { InputStreamReader bi = new InputStreamReader(jar.getInputStream(entry)); BufferedReader br = new BufferedReader(bi); String line; Pattern p = Pattern.compile(myDevice); do { line = br.readLine(); if (line == null) { break; } Matcher m = p.matcher(line); if (m.find()) { finded = true; break; } } while (true); bi.close(); } catch (IOException e) { // TODO Auto-generated catch block } } try { jar.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return finded; }
From source file:com.zb.app.common.file.FileUtils.java
public static void unJar(File jarFile, File toDir) throws IOException { JarFile jar = new JarFile(jarFile); try {/* w w w . jav a 2 s . co m*/ Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory()) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString()); } } OutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } } finally { out.close(); } } finally { in.close(); } } } } finally { jar.close(); } }
From source file:com.cisco.dbds.utils.configfilehandler.ConfigFileHandler.java
/** * Load jar cong file.//from w ww . j av a 2 s . c om * * @param Utilclass the utilclass */ public static void loadJarCongFile(Class Utilclass) { try { String path = Utilclass.getResource("").getPath(); path = path.substring(6, path.length() - 1); path = path.split("!")[0]; System.out.println(path); JarFile jarFile = new JarFile(path); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (entry.getName().contains(".properties")) { System.out.println("Jar File Property File: " + entry.getName()); JarEntry fileEntry = jarFile.getJarEntry(entry.getName()); InputStream input = jarFile.getInputStream(fileEntry); setSystemvariable(input); InputStreamReader isr = new InputStreamReader(input); BufferedReader reader = new BufferedReader(isr); String line; while ((line = reader.readLine()) != null) { System.out.println("Jar file" + line); } reader.close(); } } jarFile.close(); } catch (Exception e) { System.out.println("Jar file reading Error"); } }
From source file:com.thoughtworks.go.agent.common.util.JarUtil.java
public static String getManifestKey(File aJarFile, String key) { try (JarFile jarFile = new JarFile(aJarFile)) { return getManifestKey(jarFile, key); } catch (IOException e) { LOG.error("Exception while trying to read key {} from manifest of {}", key, aJarFile, e); }/* w ww . java2 s . c o m*/ return null; }
From source file:com.asual.summer.onejar.OneJarServer.java
private static String getCurrentWarFile() throws IOException { JarFile jarFile = new JarFile(System.getProperty("java.class.path")); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.endsWith(".war")) { File war = new File(new File(System.getProperty("java.io.tmpdir")), "summer-onejar-" + System.currentTimeMillis() + ".war"); InputStream input = jarFile.getInputStream(new ZipEntry(name)); FileOutputStream output = new FileOutputStream(war); IOUtils.copy(input, output); IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); war.deleteOnExit();//from w w w .j a va 2s. c om return war.getAbsolutePath(); } } return null; }
From source file:net.fabricmc.installer.installer.LocalVersionInstaller.java
public static void install(File mcDir, IInstallerProgress progress) throws Exception { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(Translator.getString("install.client.selectCustomJar")); fc.setFileFilter(new FileNameExtensionFilter("Jar Files", "jar")); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File inputFile = fc.getSelectedFile(); JarFile jarFile = new JarFile(inputFile); Attributes attributes = jarFile.getManifest().getMainAttributes(); String mcVersion = attributes.getValue("MinecraftVersion"); Optional<String> stringOptional = ClientInstaller.isValidInstallLocation(mcDir, mcVersion); jarFile.close();//from w w w . ja va 2 s.c o m if (stringOptional.isPresent()) { throw new Exception(stringOptional.get()); } ClientInstaller.install(mcDir, mcVersion, progress, inputFile); } else { throw new Exception("Failed to find jar"); } }
From source file:Main.java
/** * Iterates over APK (jar entries) to populate * //from ww w . j a v a2s . c o m * @param projectFile * @return * @throws IOException * @throws CertificateException */ public static List<Certificate> populateCertificate(File projectFile) throws IOException, CertificateException { List<Certificate> certList = new ArrayList<Certificate>(); JarFile jar = new JarFile(projectFile); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry entry = jarEntries.nextElement(); if (entry.getName().toLowerCase().contains(DSA) || entry.getName().toLowerCase().contains(RSA)) { certList.addAll(extractCertificate(jar, entry)); } } return certList; }
From source file:org.apache.hadoop.hbase.util.RunTrigger.java
public static void unJar(File jarFile, File toDir) throws IOException { JarFile jar = new JarFile(jarFile); try {//from w w w. j a v a 2s .c o m Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory()) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString()); } } OutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } } finally { out.close(); } } finally { in.close(); } } } } finally { jar.close(); } }
From source file:hudson.plugins.simpleupdatesite.HPI.java
public static HPI loadHPI(File file) throws IOException { JarFile jarFile = new JarFile(file); try {/*from w ww . j ava2 s .c o m*/ ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF"); HPI hpi = new HPI(); hpi.init(jarFile.getManifest().getMainAttributes(), entry.getTime()); return hpi; } finally { jarFile.close(); } }
From source file:com.katsu.dwm.reflection.JarUtils.java
/** * Return a list of resources inside the jar file that their URL start with path * @param jar/*from w w w . j a v a 2s . c o m*/ * @param path * @return */ public static List<JarEntry> getJarContent(File jar, String path) { try { JarFile jf = new JarFile(jar); Enumeration<JarEntry> enu = jf.entries(); List<JarEntry> result = new ArrayList<JarEntry>(); while (enu.hasMoreElements()) { JarEntry je = enu.nextElement(); if (je.getName().startsWith(path)) result.add(je); } return result; } catch (Exception e) { logger.error(e); } return null; }