List of usage examples for java.util.jar JarEntry isDirectory
public boolean isDirectory()
From source file:com.thoughtworks.go.domain.materials.tfs.TfsSDKCommandBuilder.java
private void explodeNatives() throws IOException { URL urlOfJar = getJarURL();/* w ww.ja v a2s . com*/ LOGGER.info("[TFS SDK] Exploding natives from {} to folder {}", urlOfJar.toString(), tempFolder.getAbsolutePath()); JarInputStream jarStream = new JarInputStream(urlOfJar.openStream()); JarEntry entry; while ((entry = jarStream.getNextJarEntry()) != null) { if (!entry.isDirectory() && entry.getName().startsWith("tfssdk/native/")) { File newFile = new File(tempFolder, entry.getName()); newFile.getParentFile().mkdirs(); LOGGER.info("[TFS SDK] Extract {} -> {}", entry.getName(), newFile); try (OutputStream fos = new FileOutputStream(newFile)) { IOUtils.copy(jarStream, fos); } } } }
From source file:org.silverpeas.applicationbuilder.ReadOnlyArchive.java
/** * Gets the available entries in the archive. It also opens the archive for reading. * * @return the entries of this archive/*from www . j a va 2 s.com*/ * @since 1.0 * @roseuid 3AAFB0770391 */ public ApplicationBuilderItem[] getEntries() { if (getJar() == null) { return null; } List<ApplicationBuilderItem> entries = new ArrayList<ApplicationBuilderItem>(getJar().size()); for (Enumeration<JarEntry> e = getJar().entries(); e.hasMoreElements();) { JarEntry jarEntry = e.nextElement(); if (!jarEntry.isDirectory()) { File oneFile = new File(jarEntry.getName()); ApplicationBuilderItem item = new ApplicationBuilderItem(oneFile.getParent(), oneFile.getName()); item.setSize(jarEntry.getSize()); entries.add(item); } } return entries.toArray(new ApplicationBuilderItem[entries.size()]); }
From source file:fr.gael.dhus.server.http.webapp.WebApplication.java
protected void extractJarFile(URL url, String configuration_folder, String dest_folder) throws IOException { final JarURLConnection connection = (JarURLConnection) url.openConnection(); if (connection != null) { Enumeration<JarEntry> entries = connection.getJarFile().entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory() && entry.getName().equals(configuration_folder)) { InputStream in = connection.getJarFile().getInputStream(entry); try { File file = new File(dest_folder); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); }/*from w ww .j a v a 2s . co m*/ OutputStream out = new FileOutputStream(file); try { IOUtils.copy(in, out); } finally { out.close(); } } finally { in.close(); } } } } }
From source file:JarHelper.java
/** * Given an InputStream on a jar file, unjars the contents into the given * directory.//w w 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:org.xwiki.webjars.internal.WebJarsExportURLFactoryActionHandler.java
private void copyResourceFromJAR(String resourcePath, String prefix, ExportURLFactoryContext factoryContext) throws IOException { // Note that we cannot use ClassLoader.getResource() to access the resource since the resourcePath may point // to a directory inside the JAR, and in this case we need to copy all resources inside that directory in the // JAR!//from w w w . jav a 2s . com JarFile jar = new JarFile(getJARFile(resourcePath)); for (Enumeration<JarEntry> enumeration = jar.entries(); enumeration.hasMoreElements();) { JarEntry entry = enumeration.nextElement(); if (entry.getName().startsWith(resourcePath) && !entry.isDirectory()) { // Copy the resource! String targetPath = prefix + entry.getName(); File targetLocation = new File(factoryContext.getExportDir(), targetPath); if (!targetLocation.exists()) { targetLocation.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(targetLocation); InputStream is = jar.getInputStream(entry); IOUtils.copy(is, fos); fos.close(); is.close(); } } } jar.close(); }
From source file:de.micromata.tpsb.doc.sources.JarSourceFileRepository.java
@Override public Collection<JavaSourceFileHolder> getSources() { List<JavaSourceFileHolder> fileContentList = new ArrayList<JavaSourceFileHolder>(); for (String jarFileName : getLocations()) { try {/*from ww w . j av a 2s. c om*/ JarFile jarFile; jarFile = new JarFile(jarFileName); Enumeration<? extends ZipEntry> jarEntryEnum = jarFile.entries(); while (jarEntryEnum.hasMoreElements()) { JarEntry jarEntry = (JarEntry) jarEntryEnum.nextElement(); // nur Java-Dateien beachten if (jarEntry.isDirectory() || StringUtils.endsWith(jarEntry.getName(), ".java") == false) { continue; } String javaFilename = jarEntry.getName(); String javaFileContent = getContents(jarFile, jarEntry); if (StringUtils.isBlank(javaFileContent) == true) { continue; } JavaSourceFileHolder fileHolder = new JavaSourceFileHolder(javaFilename, javaFileContent); fileHolder.setSource(Source.Jar); fileHolder.setOrigin(jarFileName); fileContentList.add(fileHolder); } } catch (IOException e) { e.printStackTrace(); } } return fileContentList; }
From source file:net.erdfelt.android.sdkfido.local.JarListing.java
private final void loadJar(File jarfile) throws IOException { JarFile jar = null;//from w ww . j a v a 2s . c om try { String name; jar = new JarFile(jarfile); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); name = entry.getName(); add(name); if (!entry.isDirectory() && name.endsWith(".class")) { classlist.add(name); } } } finally { if (jar != null) { jar.close(); } } }
From source file:fr.gael.dhus.server.http.web.WebApplication.java
protected void extractJarFolder(URL url, String configuration_folder, String dest_folder) throws IOException { final JarURLConnection connection = (JarURLConnection) url.openConnection(); if (connection != null) { Enumeration<JarEntry> entries = connection.getJarFile().entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory() && entry.getName().startsWith(configuration_folder)) { InputStream in = connection.getJarFile().getInputStream(entry); try { File file = new File(dest_folder, entry.getName().substring(configuration_folder.length())); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); }//from w w w .ja v a 2 s . c o m OutputStream out = new FileOutputStream(file); try { IOUtils.copy(in, out); } finally { out.close(); } } finally { in.close(); } } } } }
From source file:org.xwiki.webjars.internal.FilesystemResourceReferenceSerializer.java
private void copyResourceFromJAR(String resourcePrefix, String resourceName, String targetPrefix, FilesystemExportContext exportContext) throws IOException { // Note that we cannot use ClassLoader.getResource() to access the resource since the resourcePath may point // to a directory inside the JAR, and in this case we need to copy all resources inside that directory in the // JAR!/*w ww .j a v a 2s .co m*/ String resourcePath = String.format("%s/%s", resourcePrefix, resourceName); JarFile jar = new JarFile(getJARFile(resourcePath)); for (Enumeration<JarEntry> enumeration = jar.entries(); enumeration.hasMoreElements();) { JarEntry entry = enumeration.nextElement(); if (entry.getName().startsWith(resourcePath) && !entry.isDirectory()) { // Copy the resource! // TODO: Won't this cause collisions if the same resource is available on several subwikis for example? String targetPath = targetPrefix + entry.getName().substring(resourcePrefix.length()); File targetLocation = new File(exportContext.getExportDir(), targetPath); if (!targetLocation.exists()) { targetLocation.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(targetLocation); InputStream is = jar.getInputStream(entry); IOUtils.copy(is, fos); fos.close(); is.close(); } } } jar.close(); }
From source file:org.xwiki.webjars.internal.FilesystemResourceReferenceCopier.java
void copyResourceFromJAR(String resourcePrefix, String resourceName, String targetPrefix, FilesystemExportContext exportContext) throws IOException { // Note that we cannot use ClassLoader.getResource() to access the resource since the resourcePath may point // to a directory inside the JAR, and in this case we need to copy all resources inside that directory in the // JAR!/*from w w w . j a va 2s . c o m*/ String resourcePath = String.format(CONCAT_PATH_FORMAT, resourcePrefix, resourceName); JarFile jar = new JarFile(getJARFile(resourcePath)); try { for (Enumeration<JarEntry> enumeration = jar.entries(); enumeration.hasMoreElements();) { JarEntry entry = enumeration.nextElement(); if (entry.getName().startsWith(resourcePath) && !entry.isDirectory()) { // Copy the resource! // TODO: Won't this cause collisions if the same resource is available on several subwikis // for example? String targetPath = targetPrefix + entry.getName().substring(resourcePrefix.length()); File targetLocation = new File(exportContext.getExportDir(), targetPath); if (!targetLocation.exists()) { targetLocation.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(targetLocation); InputStream is = jar.getInputStream(entry); IOUtils.copy(is, fos); fos.close(); is.close(); } } } } finally { jar.close(); } }