List of usage examples for java.util.jar JarOutputStream putNextEntry
public void putNextEntry(ZipEntry ze) throws IOException
From source file:rubah.tools.ConversionClassGenerator.java
public void addConversionClassesToJar(JarOutputStream jos, Clazz cl) throws IOException { jos.putNextEntry(new JarEntry(this.getType(cl).getInternalName() + ".class")); IOUtils.write(this.getClassBytes(cl), jos); }
From source file:org.apache.hadoop.mapred.TestLocalJobSubmission.java
private Path makeJar(Path p) throws IOException { FileOutputStream fos = new FileOutputStream(new File(p.toString())); JarOutputStream jos = new JarOutputStream(fos); ZipEntry ze = new ZipEntry("test.jar.inside"); jos.putNextEntry(ze); jos.write(("inside the jar!").getBytes()); jos.closeEntry();/* w w w .j a v a2 s. c om*/ jos.close(); return p; }
From source file:de.fhg.igd.mapviewer.server.file.FileTiler.java
/** * Creates a Jar archive that includes the given list of files * //w w w . java2 s . c o m * @param archiveFile the name of the jar archive file * @param tobeJared the files to be included in the jar file * * @return if the operation was successful */ public static boolean createJarArchive(File archiveFile, List<File> tobeJared) { try { byte buffer[] = new byte[BUFFER_SIZE]; // Open archive file FileOutputStream stream = new FileOutputStream(archiveFile); JarOutputStream out = new JarOutputStream(stream, new Manifest()); for (int i = 0; i < tobeJared.size(); i++) { if (tobeJared.get(i) == null || !tobeJared.get(i).exists() || tobeJared.get(i).isDirectory()) continue; // Just in case... log.debug("Adding " + tobeJared.get(i).getName()); // Add archive entry JarEntry jarAdd = new JarEntry(tobeJared.get(i).getName()); jarAdd.setTime(tobeJared.get(i).lastModified()); out.putNextEntry(jarAdd); // Write file to archive FileInputStream in = new FileInputStream(tobeJared.get(i)); while (true) { int nRead = in.read(buffer, 0, buffer.length); if (nRead <= 0) break; out.write(buffer, 0, nRead); } in.close(); } out.close(); stream.close(); log.info("Adding completed OK"); return true; } catch (Exception e) { log.error("Creating jar file failed", e); return false; } }
From source file:com.opensymphony.xwork2.util.fs.JarEntryRevisionTest.java
private String createJarFile(long time) throws Exception { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); Path jarPath = Paths//from www . jav a 2 s. c o m .get(Thread.currentThread().getContextClassLoader().getResource("xwork-jar.jar").toURI()) .getParent(); File jarFile = jarPath.resolve("JarEntryRevisionTest_testNeedsReloading.jar").toFile(); FileOutputStream fos = new FileOutputStream(jarFile, false); JarOutputStream target = new JarOutputStream(fos, manifest); target.putNextEntry(new ZipEntry("com/opensymphony/xwork2/util/fs/")); ZipEntry entry = new ZipEntry("com/opensymphony/xwork2/util/fs/JarEntryRevisionTest.class"); entry.setTime(time); target.putNextEntry(entry); InputStream source = getClass() .getResourceAsStream("/com/opensymphony/xwork2/util/fs/JarEntryRevisionTest.class"); IOUtils.copy(source, target); source.close(); target.closeEntry(); target.close(); fos.close(); return jarFile.toURI().toURL().toExternalForm(); }
From source file:com.asual.summer.onejar.OneJarMojo.java
private void putEntry(JarOutputStream out, InputStream in, ZipEntry entry) throws IOException { out.putNextEntry(entry); IOUtils.copy(in, out);//from w w w.j av a 2 s . co m out.closeEntry(); }
From source file:org.apache.hadoop.util.TestApplicationClassLoader.java
private File makeTestJar() throws IOException { File jarFile = new File(testDir, "test.jar"); JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile)); ZipEntry entry = new ZipEntry("resource.txt"); out.putNextEntry(entry); out.write("hello".getBytes()); out.closeEntry();/*from ww w. jav a2s. com*/ out.close(); return jarFile; }
From source file:com.enderville.enderinstaller.util.InstallScript.java
/** * Repackages all the files in the tmp directory to the new minecraft.jar * * @param tmp The temp directory where mods were installed. * @param mcjar The location to save the new minecraft.jar. * @throws IOException//from w w w . j av a2 s . co m */ public static void repackMCJar(File tmp, File mcjar) throws IOException { byte[] dat = new byte[4 * 1024]; JarOutputStream jarout = new JarOutputStream(FileUtils.openOutputStream(mcjar)); Queue<File> queue = new LinkedList<File>(); for (File f : tmp.listFiles()) { queue.add(f); } while (!queue.isEmpty()) { File f = queue.poll(); if (f.isDirectory()) { for (File child : f.listFiles()) { queue.add(child); } } else { //TODO need a better way to do this String name = f.getPath().substring(tmp.getPath().length() + 1); //TODO is this formatting really required for jars? name = name.replace("\\", "/"); if (f.isDirectory() && !name.endsWith("/")) { name = name + "/"; } JarEntry entry = new JarEntry(name); jarout.putNextEntry(entry); FileInputStream in = new FileInputStream(f); int len = -1; while ((len = in.read(dat)) > 0) { jarout.write(dat, 0, len); } in.close(); } jarout.closeEntry(); } jarout.close(); }
From source file:org.apache.hadoop.filecache.TestMRWithDistributedCache.java
private Path makeJar(Path p, int index) throws FileNotFoundException, IOException { FileOutputStream fos = new FileOutputStream(new File(p.toString())); JarOutputStream jos = new JarOutputStream(fos); ZipEntry ze = new ZipEntry("distributed.jar.inside" + index); jos.putNextEntry(ze); jos.write(("inside the jar!" + index).getBytes()); jos.closeEntry();/* w w w .ja v a 2 s .c o m*/ jos.close(); return p; }
From source file:org.sakaiproject.kernel.component.core.test.ComponentLoaderServiceImplTest.java
/** * @param file//www . j a v a2 s . c o m * @throws IOException */ private void createComponent(File f, String component) throws IOException { if (f.getParentFile().mkdirs()) { if (debug) LOG.debug("Created Directory " + f); } JarOutputStream jarOutput = new JarOutputStream(new FileOutputStream(f)); JarEntry jarEntry = new JarEntry("SAKAI-INF/component.xml"); jarOutput.putNextEntry(jarEntry); String componentXml = ResourceLoader.readResource(component, this.getClass().getClassLoader()); jarOutput.write(componentXml.getBytes("UTF-8")); jarOutput.closeEntry(); jarOutput.close(); }
From source file:org.sourcepit.osgifier.core.packaging.Repackager.java
private void rePackageJarFile(File srcJarFile, final Manifest manifest, BundleLocalization localization, final JarOutputStream destJarOut, Collection<String> pathFilters) throws IOException { destJarOut.putNextEntry(new JarEntry(JarFile.MANIFEST_NAME)); writeManifest(manifest, destJarOut); destJarOut.closeEntry();//from w w w. j av a 2s . c o m if (localization != null) { final Set<String> paths = BundleLocalizationWriter.write(destJarOut, manifest, localization).keySet(); pathFilters = pathFilters == null ? new HashSet<String>() : new HashSet<String>(pathFilters); for (String path : paths) { pathFilters.add("!" + path); } } final PathMatcher pathMatcher = pathFilters == null ? DEFAULT_CONTENT_MATCHER : createJarContentMatcher(pathFilters); new IOOperation<JarInputStream>(jarIn(buffIn(fileIn(srcJarFile)))) { @Override protected void run(JarInputStream srcJarIn) throws IOException { copyJarContents(srcJarIn, destJarOut, pathMatcher); } }.run(); }