jaxws/src/jdk.xml.bind/share/classes/com/sun/codemodel/internal/writer/ZipCodeWriter.java
changeset 42124 640a383428fb
parent 25871 b80b84e87032
equal deleted inserted replaced
42002:3ee4e7827413 42124:640a383428fb
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    47      */
    47      */
    48     public ZipCodeWriter( OutputStream target ) {
    48     public ZipCodeWriter( OutputStream target ) {
    49         zip = new ZipOutputStream(target);
    49         zip = new ZipOutputStream(target);
    50         // nullify the close method.
    50         // nullify the close method.
    51         filter = new FilterOutputStream(zip){
    51         filter = new FilterOutputStream(zip){
       
    52             @Override
    52             public void close() {}
    53             public void close() {}
    53         };
    54         };
    54     }
    55     }
    55 
    56 
    56     private final ZipOutputStream zip;
    57     private final ZipOutputStream zip;
    57 
    58 
    58     private final OutputStream filter;
    59     private final OutputStream filter;
    59 
    60 
       
    61     @Override
    60     public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    62     public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    61         String name = fileName;
    63         final String name = pkg == null || pkg.isUnnamed() ? fileName : toDirName(pkg)+fileName;
    62         if(!pkg.isUnnamed())    name = toDirName(pkg)+name;
       
    63 
       
    64         zip.putNextEntry(new ZipEntry(name));
    64         zip.putNextEntry(new ZipEntry(name));
    65         return filter;
    65         return filter;
    66     }
    66     }
    67 
    67 
    68     /** Converts a package name to the directory name. */
    68     /** Converts a package name to the directory name. */
    69     private static String toDirName( JPackage pkg ) {
    69     private static String toDirName( JPackage pkg ) {
    70         return pkg.name().replace('.','/')+'/';
    70         return pkg.name().replace('.','/')+'/';
    71     }
    71     }
    72 
    72 
       
    73     @Override
    73     public void close() throws IOException {
    74     public void close() throws IOException {
    74         zip.close();
    75         zip.close();
    75     }
    76     }
    76 
    77 
    77 }
    78 }