80 private boolean closed = false;
81
82 private final ZipCoder zc;
83
84 private static int version(ZipEntry e) throws ZipException {
85 switch (e.method) {
86 case DEFLATED: return 20;
87 case STORED: return 10;
88 default: throw new ZipException("unsupported compression method");
89 }
90 }
91
92 /**
93 * Checks to make sure that this stream has not been closed.
94 */
95 private void ensureOpen() throws IOException {
96 if (closed) {
97 throw new IOException("Stream closed");
98 }
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);
215 if (e.size == -1) {
216 e.size = e.csize;
217 } else if (e.csize == -1) {
218 e.csize = e.size;
219 } else if (e.size != e.csize) {
220 throw new ZipException(
221 "STORED entry where compressed != uncompressed size");
222 }
223 if (e.size == -1 || e.crc == -1) {
224 throw new ZipException(
225 "STORED entry missing size, compressed size, or crc-32");
226 }
227 break;
228 default:
229 throw new ZipException("unsupported compression method");
230 }
231 if (! names.add(e.name)) {
232 throw new ZipException("duplicate entry: " + e.name);
233 }
234 if (zc.isUTF8())
235 e.flag |= EFS;
236 current = new XEntry(e, written);
237 xentries.add(current);
238 writeLOC(current);
239 }
240
241 /**
242 * Closes the current ZIP entry and positions the stream for writing
243 * the next entry.
244 * @exception ZipException if a ZIP format error has occurred
245 * @exception IOException if an I/O error has occurred
246 */
247 public void closeEntry() throws IOException {
248 ensureOpen();
249 if (current != null) {
250 ZipEntry e = current.entry;
251 switch (e.method) {
252 case DEFLATED:
253 def.finish();
254 while (!def.finished()) {
255 deflate();
|
80 private boolean closed = false;
81
82 private final ZipCoder zc;
83
84 private static int version(ZipEntry e) throws ZipException {
85 switch (e.method) {
86 case DEFLATED: return 20;
87 case STORED: return 10;
88 default: throw new ZipException("unsupported compression method");
89 }
90 }
91
92 /**
93 * Checks to make sure that this stream has not been closed.
94 */
95 private void ensureOpen() throws IOException {
96 if (closed) {
97 throw new IOException("Stream closed");
98 }
99 }
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, StandardCharsets.UTF_8);
216 if (e.size == -1) {
217 e.size = e.csize;
218 } else if (e.csize == -1) {
219 e.csize = e.size;
220 } else if (e.size != e.csize) {
221 throw new ZipException(
222 "STORED entry where compressed != uncompressed size");
223 }
224 if (e.size == -1 || e.crc == -1) {
225 throw new ZipException(
226 "STORED entry missing size, compressed size, or crc-32");
227 }
228 break;
229 default:
230 throw new ZipException("unsupported compression method");
231 }
232 if (! names.add(e.name)) {
233 throw new ZipException("duplicate entry: " + e.name);
234 }
235 if (zc.isUTF8())
236 e.flag |= USE_UTF8;
237 current = new XEntry(e, written);
238 xentries.add(current);
239 writeLOC(current);
240 }
241
242 /**
243 * Closes the current ZIP entry and positions the stream for writing
244 * the next entry.
245 * @exception ZipException if a ZIP format error has occurred
246 * @exception IOException if an I/O error has occurred
247 */
248 public void closeEntry() throws IOException {
249 ensureOpen();
250 if (current != null) {
251 ZipEntry e = current.entry;
252 switch (e.method) {
253 case DEFLATED:
254 def.finish();
255 while (!def.finished()) {
256 deflate();
|