< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/JarWriter.java

Print this page




  37     private final Log log;
  38 
  39     private final Writer writer;
  40 
  41     public JarWriter(Context ctx, Writer writer) {
  42         this.log = ctx.log;
  43         this.writer = writer;
  44     }
  45 
  46     public void writeJarFile(Path jarpath, String[] args) throws IOException {
  47         log.print(Level.INFO, () -> "Collecting jar file " + jarpath);
  48         try (OutputStream os = Files.newOutputStream(jarpath, CREATE, TRUNCATE_EXISTING, WRITE);
  49                 JarOutputStream jar = new JarOutputStream(os)) {
  50             writeJarFile(jar, args);
  51         }
  52     }
  53 
  54     public void writeJarFile(JarOutputStream jar, String[] args) {
  55         writer.results().forEach((cls, bytes) -> {
  56                 try {
  57                     String path = cls.replace('.', File.separatorChar) + ".class";
  58                     log.print(Level.FINE, () -> "Add " + path);
  59                     jar.putNextEntry(new ZipEntry(path));
  60                     jar.write(bytes);
  61                     jar.closeEntry();
  62                 } catch (IOException ioe) {
  63                     throw new UncheckedIOException(ioe);
  64                 }
  65             });
  66 
  67             try {
  68                 jar.putNextEntry(new ZipEntry(Writer.JEXTRACT_MANIFEST));
  69                 jar.write(writer.getJextractProperties(args));
  70                 jar.closeEntry();
  71             } catch (IOException ioe) {
  72                 throw new UncheckedIOException(ioe);
  73             }
  74     }
  75 }


  37     private final Log log;
  38 
  39     private final Writer writer;
  40 
  41     public JarWriter(Context ctx, Writer writer) {
  42         this.log = ctx.log;
  43         this.writer = writer;
  44     }
  45 
  46     public void writeJarFile(Path jarpath, String[] args) throws IOException {
  47         log.print(Level.INFO, () -> "Collecting jar file " + jarpath);
  48         try (OutputStream os = Files.newOutputStream(jarpath, CREATE, TRUNCATE_EXISTING, WRITE);
  49                 JarOutputStream jar = new JarOutputStream(os)) {
  50             writeJarFile(jar, args);
  51         }
  52     }
  53 
  54     public void writeJarFile(JarOutputStream jar, String[] args) {
  55         writer.results().forEach((cls, bytes) -> {
  56                 try {
  57                     String path = cls.replace('.', '/') + ".class";
  58                     log.print(Level.FINE, () -> "Add " + path);
  59                     jar.putNextEntry(new ZipEntry(path));
  60                     jar.write(bytes);
  61                     jar.closeEntry();
  62                 } catch (IOException ioe) {
  63                     throw new UncheckedIOException(ioe);
  64                 }
  65             });
  66 
  67             try {
  68                 jar.putNextEntry(new ZipEntry(Writer.JEXTRACT_MANIFEST));
  69                 jar.write(writer.getJextractProperties(args));
  70                 jar.closeEntry();
  71             } catch (IOException ioe) {
  72                 throw new UncheckedIOException(ioe);
  73             }
  74     }
  75 }
< prev index next >