@Override public void modifyOutputStream(JarOutputStream jarOut) throws IOException { for (String key : this.entries.keySet()) { jarOut.putNextEntry(new JarEntry(key)); jarOut.write(this.entries.get(key).getBytes()); } } }
public static void addFileToJar(JarOutputStream jar, File source, String entryName) throws IOException { try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(source))) { JarEntry entry = new JarEntry(entryName); entry.setTime(source.lastModified()); jar.putNextEntry(entry); copyStream(in, jar); jar.closeEntry(); } }
/** * {@inheritDoc} */ public void store(Map<TypeDescription, byte[]> binaryRepresentations) throws IOException { for (Map.Entry<TypeDescription, byte[]> entry : binaryRepresentations.entrySet()) { outputStream.putNextEntry(new JarEntry(entry.getKey().getInternalName() + CLASS_FILE_EXTENSION)); outputStream.write(entry.getValue()); outputStream.closeEntry(); } }
private JarOutputStream createJarWithConfigXmlEntry(File file) throws IOException { JarOutputStream jar = new JarOutputStream(new FileOutputStream(file)); ZipEntry config = new ZipEntry("config.xml"); jar.putNextEntry(config); return jar; }
JarEntry entry = new JarEntry(fileName.replace('\\', '/')); jarFile.putNextEntry(entry); streamOut = jarFile; } else { streamOut = new FileOutputStream(fileName); OutputStream streamOut = new FileOutputStream(fileName); PrintWriter writerOut = new PrintWriter(new OutputStreamWriter(streamOut)); DavaBuildFile.generate(writerOut, decompiledClasses);
JarEntry entry = new JarEntry(fileName); entry.setMethod(ZipEntry.DEFLATED); jarFile.putNextEntry(entry); streamOut = jarFile; } else { new File(fileName).getParentFile().mkdirs(); streamOut = new FileOutputStream(fileName); writerOut.close(); } else { jarFile.closeEntry();
private static Optional<Path> getOverrideClasspath(@Nullable List<Class<?>> overrideClasspath) { if (overrideClasspath == null) { return Optional.empty(); } try { Path tempJarFile = Files.createTempFile(/* prefix = */ null, /* suffix = */ ".jar"); try (OutputStream os = Files.newOutputStream(tempJarFile); JarOutputStream jos = new JarOutputStream(os)) { for (Class<?> clazz : overrideClasspath) { String entryPath = clazz.getName().replace('.', '/') + ".class"; jos.putNextEntry(new JarEntry(entryPath)); try (InputStream is = clazz.getClassLoader().getResourceAsStream(entryPath)) { ByteStreams.copy(is, jos); } } } return Optional.of(tempJarFile); } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = resourceRoot.relativize(file).toString(); jar.putNextEntry(new ZipEntry(name)); try (InputStream input = Files.newInputStream(file, StandardOpenOption.READ)) { int len; while ((len = input.read(data)) > 0) { jar.write(data, 0, len); } } return FileVisitResult.CONTINUE; } });
public void emit(String path, InputStream contents) throws IOException { ZipEntry entry = new ZipEntry(path); out.putNextEntry(entry); byte[] bytes = new byte[4096]; int read; for (;;) { read = contents.read(bytes); if (read == -1) { break; } rawByteSize += read; out.write(bytes, 0, read); } out.closeEntry(); } }
public void modifyOutputStream( JarOutputStream jos ) throws IOException { jos.putNextEntry( new JarEntry( resource ) ); new XMLOutputter( Format.getPrettyFormat() ).output( doc, jos ); doc = null; } }
JarOutputStream jarStream = new JarOutputStream(fileStream); InputStream classStream = Files.newInputStream(fullClassFile)) { ZipEntry entry = new ZipEntry(classFile.toString()); jarStream.putNextEntry(entry);
@ExpectWarning("AM_CREATES_EMPTY_JAR_FILE_ENTRY") void bug(JarOutputStream any, ZipEntry anyZipEntry) throws IOException { any.putNextEntry(anyZipEntry); any.closeEntry(); }
/** * {@inheritDoc} */ public File toJar(File file, Manifest manifest) throws IOException { if (!file.isFile() && !file.createNewFile()) { throw new IllegalArgumentException("Could not create file: " + file); } JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(file), manifest); try { for (Map.Entry<TypeDescription, byte[]> entry : getAuxiliaryTypes().entrySet()) { outputStream.putNextEntry(new JarEntry(entry.getKey().getInternalName() + CLASS_FILE_EXTENSION)); outputStream.write(entry.getValue()); outputStream.closeEntry(); } outputStream.putNextEntry(new JarEntry(typeDescription.getInternalName() + CLASS_FILE_EXTENSION)); outputStream.write(binaryRepresentation); outputStream.closeEntry(); } finally { outputStream.close(); } return file; }
private JarOutputStream createJarWithConfigXmlEntry(File file) throws IOException { JarOutputStream jar = new JarOutputStream(new FileOutputStream(file)); ZipEntry config = new ZipEntry("config.xml"); jar.putNextEntry(config); return jar; }
public void testJar(JarOutputStream jos) throws Exception { JarEntry je = new JarEntry("foo"); jos.putNextEntry(je); jos.closeEntry(); } }
if (inEntry.getMethod() == JarEntry.STORED) { outEntry = new JarEntry(inEntry); } else { outEntry = new JarEntry(name); out.putNextEntry(outEntry); out.write(buffer, 0, num);
jStream.putNextEntry(zipEntry); int count = 0; do { jStream.write(byteBuffer, 0, count); count = iStream.read(byteBuffer, 0, byteBuffer.length); } while (count != -1);
private void addClass(final Class<?> clazz, final JarOutputStream jos) throws IOException { final String className = clazz.getName(); final ZipEntry ze = new ZipEntry(className.replace(".", "/") + ".class"); jos.putNextEntry(ze); jos.write(classBytes(className)); jos.closeEntry(); }
private void createJar(JarOutputStream jarOutputStream) throws IOException { for (VirtualFile virtualFile : files.values()) { if (virtualFile.isDirectory()) { virtualFile.createJar(jarOutputStream); } else { JarEntry jarEntry = new JarEntry(virtualFile.getName().replace(File.separator, "/")); jarOutputStream.putNextEntry(jarEntry); InputStream inputStream = virtualFile.openInputStream(); IOUtils.copy(inputStream, jarOutputStream); inputStream.close(); } } }
/** * Constructs a new {@code JarOutputStream} using an output stream. The * content of the {@code Manifest} must match the JAR entry information * written subsequently to the stream. * * @param os * the {@code OutputStream} to write to * @param manifest * the {@code Manifest} to output for this JAR file. * @throws IOException * if an error occurs creating the {@code JarOutputStream}. */ public JarOutputStream(OutputStream os, Manifest manifest) throws IOException { super(os); if (manifest == null) { throw new NullPointerException("manifest == null"); } this.manifest = manifest; ZipEntry ze = new ZipEntry(JarFile.MANIFEST_NAME); putNextEntry(ze); this.manifest.write(this); closeEntry(); }