KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > util > zip > ZipOutputStream


1 /*
2  * Copyright 2005-2006 Schlichtherle IT Services
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package de.schlichtherle.util.zip;
18
19 import java.io.IOException JavaDoc;
20 import java.io.OutputStream JavaDoc;
21 import java.io.UnsupportedEncodingException JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Enumeration JavaDoc;
24
25 /**
26  * Replacement for
27  * {@link java.util.zip.ZipOutputStream java.util.zip.ZipOutputStream}.
28  * <p>
29  * This class is designed to be thread safe.
30  *
31  * @author Christian Schlichtherle
32  * @version @version@
33  * @since TrueZIP 6.4
34  */

35 public class ZipOutputStream extends BasicZipOutputStream {
36     
37     /**
38      * Creates a new ZIP output stream decorating the given output stream,
39      * using the {@link #DEFAULT_ENCODING}.
40      *
41      * @throws NullPointerException If <code>out</code> is <code>null</code>.
42      */

43     public ZipOutputStream(
44             final OutputStream JavaDoc out)
45     throws NullPointerException JavaDoc {
46         super(out);
47     }
48
49     /**
50      * Creates a new ZIP output stream decorating the given output stream.
51      *
52      * @throws NullPointerException If <code>out</code> or <code>encoding</code> is
53      * <code>null</code>.
54      * @throws UnsupportedEncodingException If encoding is not supported by
55      * this JVM.
56      */

57     public ZipOutputStream(
58             final OutputStream JavaDoc out,
59             final String JavaDoc encoding)
60     throws NullPointerException JavaDoc,
61             UnsupportedEncodingException JavaDoc {
62         super(out, encoding);
63     }
64
65     public synchronized int size() {
66         return super.size();
67     }
68
69     /**
70      * Returns a safe enumeration of clones of the ZIP entries written so far.
71      * This method takes a snapshot of the collection of all entries and
72      * enumerates their clones, so concurrent modifications or state changes
73      * do not affect this instance, the returned enumeration or the
74      * enumerated ZIP entries.
75      */

76     public synchronized Enumeration JavaDoc entries() {
77     return new Enumeration JavaDoc() {
78         Enumeration JavaDoc e = Collections.enumeration(Collections.list(
79                     ZipOutputStream.super.entries()));
80
81         public boolean hasMoreElements() {
82         return e.hasMoreElements();
83         }
84
85         public Object JavaDoc nextElement() {
86         return ((ZipEntry) e.nextElement()).clone();
87         }
88         };
89     }
90
91     /**
92      * Returns a clone of the {@link ZipEntry} for the given name or
93      * <code>null</code> if no entry with that name exists.
94      *
95      * @param name Name of the ZIP entry.
96      */

97     public synchronized ZipEntry getEntry(String JavaDoc name) {
98         ZipEntry ze = super.getEntry(name);
99         return ze != null ? (ZipEntry) ze.clone() : null;
100     }
101
102     public synchronized void setComment(String JavaDoc comment) {
103         super.setComment(comment);
104     }
105
106     public synchronized String JavaDoc getComment() {
107         return super.getComment();
108     }
109     
110     public synchronized void setLevel(int level) {
111     super.setLevel(level);
112     }
113
114     public synchronized int getLevel() {
115         return super.getLevel();
116     }
117
118     public synchronized void setMethod(short method) {
119         super.setMethod(method);
120     }
121
122     public synchronized short getMethod() {
123         return super.getMethod();
124     }
125
126     public synchronized long length() {
127         return super.length();
128     }
129
130     public synchronized final boolean busy() {
131         return super.busy();
132     }
133
134     public synchronized void putNextEntry(final ZipEntry ze, final boolean deflate)
135     throws IOException JavaDoc {
136         super.putNextEntry(ze, deflate);
137     }
138
139     public synchronized void write(byte b)
140     throws IOException JavaDoc {
141         super.write(b);
142     }
143
144     public synchronized void write(final byte[] b, final int off, final int len)
145     throws IOException JavaDoc {
146         super.write(b, off, len);
147     }
148
149     public synchronized void closeEntry() throws IOException JavaDoc {
150         super.closeEntry();
151     }
152
153     public synchronized void finish() throws IOException JavaDoc {
154         super.finish();
155     }
156
157     public synchronized void close() throws IOException JavaDoc {
158         super.close();
159     }
160 }
161
Popular Tags