< prev index next >

src/java.base/share/classes/java/util/zip/ZipOutputStream.java

Print this page
rev 49550 : 8201179: Regression due loading java.nio.charset.StandardCharsets during bootstrap
Reviewed-by: sherman


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.zip;
  27 
  28 import java.io.OutputStream;
  29 import java.io.IOException;
  30 import java.nio.charset.Charset;
  31 import java.nio.charset.StandardCharsets;
  32 import java.util.Vector;
  33 import java.util.HashSet;
  34 import static java.util.zip.ZipConstants64.*;
  35 import static java.util.zip.ZipUtils.*;


  36 import sun.security.action.GetPropertyAction;
  37 
  38 /**
  39  * This class implements an output stream filter for writing files in the
  40  * ZIP file format. Includes support for both compressed and uncompressed
  41  * entries.
  42  *
  43  * @author      David Connelly
  44  * @since 1.1
  45  */
  46 public
  47 class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
  48 
  49     /**
  50      * Whether to use ZIP64 for zip files with more than 64k entries.
  51      * Until ZIP64 support in zip implementations is ubiquitous, this
  52      * system property allows the creation of zip files which can be
  53      * read by legacy zip implementations which tolerate "incorrect"
  54      * total entry count fields, such as the ones in jdk6, and even
  55      * some in jdk7.


  99     }
 100     /**
 101      * Compression method for uncompressed (STORED) entries.
 102      */
 103     public static final int STORED = ZipEntry.STORED;
 104 
 105     /**
 106      * Compression method for compressed (DEFLATED) entries.
 107      */
 108     public static final int DEFLATED = ZipEntry.DEFLATED;
 109 
 110     /**
 111      * Creates a new ZIP output stream.
 112      *
 113      * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used
 114      * to encode the entry names and comments.
 115      *
 116      * @param out the actual output stream
 117      */
 118     public ZipOutputStream(OutputStream out) {
 119         this(out, StandardCharsets.UTF_8);
 120     }
 121 
 122     /**
 123      * Creates a new ZIP output stream.
 124      *
 125      * @param out the actual output stream
 126      *
 127      * @param charset the {@linkplain java.nio.charset.Charset charset}
 128      *                to be used to encode the entry names and comments
 129      *
 130      * @since 1.7
 131      */
 132     public ZipOutputStream(OutputStream out, Charset charset) {
 133         super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
 134         if (charset == null)
 135             throw new NullPointerException("charset is null");
 136         this.zc = ZipCoder.get(charset);
 137         usesDefaultDeflater = true;
 138     }
 139 




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.zip;
  27 
  28 import java.io.OutputStream;
  29 import java.io.IOException;
  30 import java.nio.charset.Charset;

  31 import java.util.Vector;
  32 import java.util.HashSet;
  33 import static java.util.zip.ZipConstants64.*;
  34 import static java.util.zip.ZipUtils.*;
  35 
  36 import sun.nio.cs.UTF_8;
  37 import sun.security.action.GetPropertyAction;
  38 
  39 /**
  40  * This class implements an output stream filter for writing files in the
  41  * ZIP file format. Includes support for both compressed and uncompressed
  42  * entries.
  43  *
  44  * @author      David Connelly
  45  * @since 1.1
  46  */
  47 public
  48 class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
  49 
  50     /**
  51      * Whether to use ZIP64 for zip files with more than 64k entries.
  52      * Until ZIP64 support in zip implementations is ubiquitous, this
  53      * system property allows the creation of zip files which can be
  54      * read by legacy zip implementations which tolerate "incorrect"
  55      * total entry count fields, such as the ones in jdk6, and even
  56      * some in jdk7.


 100     }
 101     /**
 102      * Compression method for uncompressed (STORED) entries.
 103      */
 104     public static final int STORED = ZipEntry.STORED;
 105 
 106     /**
 107      * Compression method for compressed (DEFLATED) entries.
 108      */
 109     public static final int DEFLATED = ZipEntry.DEFLATED;
 110 
 111     /**
 112      * Creates a new ZIP output stream.
 113      *
 114      * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used
 115      * to encode the entry names and comments.
 116      *
 117      * @param out the actual output stream
 118      */
 119     public ZipOutputStream(OutputStream out) {
 120         this(out, UTF_8.INSTANCE);
 121     }
 122 
 123     /**
 124      * Creates a new ZIP output stream.
 125      *
 126      * @param out the actual output stream
 127      *
 128      * @param charset the {@linkplain java.nio.charset.Charset charset}
 129      *                to be used to encode the entry names and comments
 130      *
 131      * @since 1.7
 132      */
 133     public ZipOutputStream(OutputStream out, Charset charset) {
 134         super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
 135         if (charset == null)
 136             throw new NullPointerException("charset is null");
 137         this.zc = ZipCoder.get(charset);
 138         usesDefaultDeflater = true;
 139     }
 140 


< prev index next >