JarFile jarFile = new JarFile(from)) { final Pack200.Packer packer = Pack200.newPacker(); packer.properties().putAll(props); packer.pack(jarFile, fos);
packer.pack(jar, bufferedStream);
JarFile jarFile = new JarFile(from)) { final Pack200.Packer packer = Pack200.newPacker(); packer.properties().putAll(props); packer.pack(jarFile, fos);
JarFile jarFile = new JarFile(from)) { final Pack200.Packer packer = Pack200.newPacker(); packer.properties().putAll(props); packer.pack(jarFile, fos);
SortedMap<String, String> props = packer.properties(); props.put(Packer.EFFORT, "9"); props.put(Packer.KEEP_FILE_ORDER, Packer.TRUE); packer.pack(in, out); System.setErr(err);
packer.properties().putAll( props ); packer.pack( jar, out );
private void pack(File jar, File pack) throws IOException, FileNotFoundException { // 387541 apparently JarFile is required to preserve jar file signatures JarFile is = new JarFile(jar); try { OutputStream os = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(pack))); try { Packer packer = newPacker(); packer.pack(is, os); } finally { close(os); } } finally { try { is.close(); } catch (IOException e) { // ignored } } }
private byte[] pack200(byte[] data) throws Exception { JarInputStream in = new JarInputStream(new ByteArrayInputStream(data)); ByteArrayOutputStream out = new ByteArrayOutputStream(); Packer packer = Pack200.newPacker(); SortedMap<String, String> props = packer.properties(); props.put(Packer.EFFORT, "9"); props.put(Packer.KEEP_FILE_ORDER, Packer.TRUE); props.put(Packer.UNKNOWN_ATTRIBUTE, Packer.PASS); final PrintStream err = new PrintStream(System.err); System.setErr(new PrintStream(ByteStreams.nullOutputStream())); packer.pack(in, out); System.setErr(err); in.close(); out.close(); return out.toByteArray(); }
/** * Packs a buffer in JAR/ZIP format into a stream in Pack200 format. * * @param source * source in JAR/ZIP format * @param output * stream in Pack200 format * @throws IOException * in case of errors with the streams */ public static void pack(final byte[] source, final OutputStream output) throws IOException { final JarInputStream jar = new JarInputStream(new ByteArrayInputStream( source)); Pack200.newPacker().pack(jar, output); }
/** * Writes this JAR to an output stream, and closes the stream. */ public <T extends OutputStream> T write(T os) throws IOException { close(); if (!(this.os instanceof ByteArrayOutputStream)) throw new IllegalStateException("Cannot write to another target if setOutputStream has been called"); final byte[] content = ((ByteArrayOutputStream) this.os).toByteArray(); if (packer != null) packer.pack(new JarInputStream(new ByteArrayInputStream(content)), os); else os.write(content); os.close(); return os; }
public void finish() throws IOException { if (!finished) { finished = true; final Pack200.Packer p = Pack200.newPacker(); if (properties != null) { p.properties().putAll(properties); } try (JarInputStream ji = new JarInputStream(streamBridge.getInput())) { p.pack(ji, originalOutput); } } } }
public void finish() throws IOException { if (!finished) { finished = true; final Pack200.Packer p = Pack200.newPacker(); if (properties != null) { p.properties().putAll(properties); } try (JarInputStream ji = new JarInputStream(streamBridge.getInput())) { p.pack(ji, originalOutput); } } } }
private void packJar(JarInputStream jarInputStream, OutputStream outputStream) throws IOException { try (LzmaOutputStream lzmaOutputStream = new LzmaOutputStream.Builder(outputStream).useEndMarkerMode(true).build()) { Pack200.newPacker().pack(jarInputStream, lzmaOutputStream); } }
private Packer newPacker() { Packer packer = Pack200.newPacker(); // From Pack200.Packer javadoc: // ... the segment limit may also need to be set to "-1", // to prevent accidental variation of segment boundaries as class file sizes change slightly packer.properties().put(Packer.SEGMENT_LIMIT, "-1"); return packer; }
private Pack200.Packer createPack200Packer(PackFile packFile) { Pack200.Packer packer = Pack200.newPacker(); Map<String, String> defaultPackerProperties = packer.properties(); Map<String,String> localPackerProperties = packFile.getPack200Properties(); if (localPackerProperties != null) { defaultPackerProperties.putAll(localPackerProperties); } return packer; }
public void createArchive() throws ArchiverException, IOException { // Create the Packer object Packer packer = Pack200.newPacker(); packer.properties().putAll(getProperties()); JarFile jarFile = new JarFile(getSourceJar()); FileOutputStream fos = new FileOutputStream(getDestFile()); // Call the packer packer.pack(jarFile, fos); jarFile.close(); fos.close(); }
private static void pack200(Path jarPath, Path toPack200Path, String pluginKey) { Profiler profiler = Profiler.create(LOG); profiler.startInfo("Compressing plugin " + pluginKey + " [pack200]"); try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(jarPath))); OutputStream out = new GZIPOutputStream(new BufferedOutputStream(Files.newOutputStream(toPack200Path)))) { Pack200.newPacker().pack(in, out); } catch (IOException e) { throw new IllegalStateException(String.format("Fail to pack200 plugin [%s] '%s' to '%s'", pluginKey, jarPath, toPack200Path), e); } profiler.stopInfo(); }
/** * Enqueue download of file with a MD5 that may not be returned (null) or not valid */ private void enqueueCompressedDownload(FileAndMd5 jar, boolean validMd5) throws IOException { Buffer body = new Buffer(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(jar.file.toPath()))); OutputStream output = new GZIPOutputStream(new BufferedOutputStream(bytes))) { Pack200.newPacker().pack(in, output); } body.write(bytes.toByteArray()); MockResponse response = new MockResponse().setBody(body); response.setHeader("Sonar-MD5", validMd5 ? DigestUtils.md5Hex(bytes.toByteArray()) : "invalid_hash"); response.setHeader("Sonar-UncompressedMD5", jar.md5); response.setHeader("Sonar-Compression", "pack200"); server.enqueue(response); }
public void finish() throws IOException { if (!finished) { finished = true; final Pack200.Packer p = Pack200.newPacker(); if (properties != null) { p.properties().putAll(properties); } try (JarInputStream ji = new JarInputStream(streamBridge.getInput())) { p.pack(ji, originalOutput); } } } }
private File packAndUnpackJar(File source) throws IOException { File packed = temp.newFile(); try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(source.toPath()))); OutputStream out = new GZIPOutputStream(new BufferedOutputStream(Files.newOutputStream(packed.toPath())))) { Pack200.newPacker().pack(in, out); } File to = temp.newFile(); try (InputStream input = new GZIPInputStream(new BufferedInputStream(Files.newInputStream(packed.toPath()))); JarOutputStream output = new JarOutputStream(new BufferedOutputStream(Files.newOutputStream(to.toPath())))) { Pack200.newUnpacker().unpack(input, output); } catch (IOException e) { throw new IllegalStateException(e); } return to; }