/** * The minimum requirement to have a "valid" archive plugin is to include * findbugs.xml, messages.xml and MANIFEST.MF files. The rest of the * resources are load using the parent ClassLoader (Not requires to be in * the jar). * <p> * Instead of building a file on disk, the result of the stream is kept in * memory and return as a byte array. * * @return * @throws IOException * @throws URISyntaxException */ private byte[] buildFakePluginJar() throws IOException, URISyntaxException { ClassLoader cl = getClass().getClassLoader(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); JarOutputStream jar = new JarOutputStream(buffer); final URL metadata = cl.getResource("metadata"); if (metadata != null) { final File dir = new File(metadata.toURI()); //Add files to the jar stream addFilesToStream(cl, jar, dir, ""); } jar.finish(); jar.close(); return buffer.toByteArray(); }
public void createJar(OutputStream outputStream) { try { JarOutputStream jarOutputStream = new JarOutputStream(outputStream); createJar(jarOutputStream); jarOutputStream.finish(); } catch (IOException e) { LOGGER.error("", e); } }
"com/google/re2j", new File(projectRoot, "/build/resources/test/com/google/re2j/RE2J-Fake.gwt.xml")); jar.finish(); jar.close();
/** * @param job * @throws IOException * @throws FileNotFoundException */ private void uploadJobJar(Job job) throws IOException, FileNotFoundException { File jobJarFile = new File(TEST_ROOT_DIR, "jobjar-on-dfs.jar"); JarOutputStream jstream = new JarOutputStream(new FileOutputStream(jobJarFile)); ZipEntry ze = new ZipEntry("lib/lib1.jar"); jstream.putNextEntry(ze); jstream.closeEntry(); ze = new ZipEntry("lib/lib2.jar"); jstream.putNextEntry(ze); jstream.closeEntry(); jstream.finish(); jstream.close(); job.setJar(jobJarFile.toURI().toString()); }
/** * @return * @throws IOException */ public InputStream getInputStream() throws IOException { if ( jarOS != null && file != null ){ if ( hasEntries() ){ jarOS.finish(); } postFinishJar( file ); return new FileInputStream( file ); } return null; }
/** * @return * @throws IOException */ public InputStream getInputStream() throws IOException { if ( jarOS != null && file != null ){ if ( hasEntries() ){ jarOS.finish(); } postFinishJar( file ); return new FileInputStream( file ); } return null; }
private Map<String, Class> defineDynamic(Set<String> classNames, byte[] dalvikBytecode) throws IOException, ClassNotFoundException { File tmpDex = new File(tmpDynamicFiles, UUID.randomUUID().toString() + ".jar"); Map<String, Class> result = new LinkedHashMap<String, Class>(); try { FileOutputStream fos = new FileOutputStream(tmpDex); JarOutputStream jar = new JarOutputStream(fos, makeManifest()); JarEntry classes = new JarEntry(DEX_IN_JAR_NAME); classes.setSize(dalvikBytecode.length); jar.putNextEntry(classes); jar.write(dalvikBytecode); jar.closeEntry(); jar.finish(); jar.flush(); fos.flush(); fos.close(); jar.close(); DexClassLoader loader = new DexClassLoader(tmpDex.getAbsolutePath(), tmpDynamicFiles.getAbsolutePath(), null, classLoader); for (String className : classNames) { result.put(className, loader.loadClass(className)); } return result; } finally { tmpDex.delete(); } }
/** * Unpack a stream in Pack200 format into a stream in JAR/ZIP format. * * @param input * stream in Pack200 format * @return stream in JAR/ZIP format * @throws IOException * in case of errors with the streams */ public static InputStream unpack(final InputStream input) throws IOException { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final JarOutputStream jar = new JarOutputStream(buffer); Pack200.newUnpacker().unpack(new NoCloseInput(input), jar); jar.finish(); return new ByteArrayInputStream(buffer.toByteArray()); }
public boolean process() throws IOException { boolean processed = false; final JarInputStream inputStream = new JarInputStream(source); Manifest manifest = inputStream.getManifest(); if (manifest == null) { manifest = new Manifest(); } if (opts.sourceFilePath != null) { final Map<String, Attributes> entries = manifest.getEntries(); Attributes attributes = new Attributes(); attributes.put(new Attributes.Name("Source-File-Path"), opts.sourceFilePath); entries.put("PatchLib", attributes); } final JarOutputStream outputStream = new JarOutputStream(target, manifest); JarEntry entry; while ((entry = inputStream.getNextJarEntry()) != null) { // Only process .class file processed |= processEntry(inputStream, outputStream, entry); } outputStream.finish(); return processed; }
jos.write(entryContent); jos.closeEntry(); jos.finish(); out.flush(); return out.toByteArray();
jos.write(entryContent); jos.closeEntry(); jos.finish(); out.flush(); return out.toByteArray();
jarOut.finish(); jarOut.flush(); closeOutput(out);
jarOut.finish(); jarOut.flush(); closeOutput(out);
jarOut.finish(); jarOut.flush(); closeOutput(out);
jarOut.finish(); jarOut.flush(); closeOutput(out);
jarOut.finish(); jarOut.flush(); closeOutput(out);
jarOut.finish(); jarOut.flush(); closeOutput(out);
jos.finish(); // FLUSH is not sufficient!!!!