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
35 /**
36 * This class implements an output stream filter for writing files in the
37 * ZIP file format. Includes support for both compressed and uncompressed
38 * entries.
39 *
40 * @author David Connelly
41 */
42 public
43 class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
44
45 private static class XEntry {
46 public final ZipEntry entry;
47 public final long offset;
48 public XEntry(ZipEntry entry, long offset) {
49 this.entry = entry;
50 this.offset = offset;
83 }
84 /**
85 * Compression method for uncompressed (STORED) entries.
86 */
87 public static final int STORED = ZipEntry.STORED;
88
89 /**
90 * Compression method for compressed (DEFLATED) entries.
91 */
92 public static final int DEFLATED = ZipEntry.DEFLATED;
93
94 /**
95 * Creates a new ZIP output stream.
96 *
97 * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used
98 * to encode the entry names and comments.
99 *
100 * @param out the actual output stream
101 */
102 public ZipOutputStream(OutputStream out) {
103 this(out, Charset.forName("UTF-8"));
104 }
105
106 /**
107 * Creates a new ZIP output stream.
108 *
109 * @param out the actual output stream
110 *
111 * @param charset the {@linkplain java.nio.charset.Charset charset}
112 * to be used to encode the entry names and comments
113 *
114 * @since 1.7
115 */
116 public ZipOutputStream(OutputStream out, Charset charset) {
117 super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
118 if (charset == null)
119 throw new NullPointerException("charset is null");
120 this.zc = ZipCoder.get(charset);
121 usesDefaultDeflater = true;
122 }
123
|
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.StandardCharset;
32 import java.util.Vector;
33 import java.util.HashSet;
34 import static java.util.zip.ZipConstants64.*;
35
36 /**
37 * This class implements an output stream filter for writing files in the
38 * ZIP file format. Includes support for both compressed and uncompressed
39 * entries.
40 *
41 * @author David Connelly
42 */
43 public
44 class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
45
46 private static class XEntry {
47 public final ZipEntry entry;
48 public final long offset;
49 public XEntry(ZipEntry entry, long offset) {
50 this.entry = entry;
51 this.offset = offset;
84 }
85 /**
86 * Compression method for uncompressed (STORED) entries.
87 */
88 public static final int STORED = ZipEntry.STORED;
89
90 /**
91 * Compression method for compressed (DEFLATED) entries.
92 */
93 public static final int DEFLATED = ZipEntry.DEFLATED;
94
95 /**
96 * Creates a new ZIP output stream.
97 *
98 * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used
99 * to encode the entry names and comments.
100 *
101 * @param out the actual output stream
102 */
103 public ZipOutputStream(OutputStream out) {
104 this(out, StandardCharset.UTF_8);
105 }
106
107 /**
108 * Creates a new ZIP output stream.
109 *
110 * @param out the actual output stream
111 *
112 * @param charset the {@linkplain java.nio.charset.Charset charset}
113 * to be used to encode the entry names and comments
114 *
115 * @since 1.7
116 */
117 public ZipOutputStream(OutputStream out, Charset charset) {
118 super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
119 if (charset == null)
120 throw new NullPointerException("charset is null");
121 this.zc = ZipCoder.get(charset);
122 usesDefaultDeflater = true;
123 }
124
|