01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package java.util.jar;
19:
20: import java.io.IOException;
21: import java.io.OutputStream;
22: import java.util.zip.ZipEntry;
23: import java.util.zip.ZipOutputStream;
24:
25: /**
26: * The JarOutputStream is used to output data in JarFile format.
27: */
28: public class JarOutputStream extends ZipOutputStream {
29:
30: private Manifest manifest;
31:
32: /**
33: * Constructs a new JarOutputStream using os as the underlying stream.
34: * Manifest information for the JarFile to be written is obtained from the
35: * parameter Manifest, mf.
36: *
37: * @param os
38: * The OutputStream to write to
39: * @param mf
40: * The Manifest to output for this Jar.
41: * @exception IOException
42: * If an error occurs creating the JarOutputStream
43: */
44: public JarOutputStream(OutputStream os, Manifest mf)
45: throws IOException {
46: super (os);
47: if (mf == null) {
48: throw new NullPointerException();
49: }
50: manifest = mf;
51: ZipEntry ze = new ZipEntry(JarFile.MANIFEST_NAME);
52: putNextEntry(ze);
53: manifest.write(this );
54: closeEntry();
55: }
56:
57: /**
58: * Constructs a new JarOutputStream using os as the underlying stream.
59: *
60: * @param os
61: * The OutputStream to write to
62: * @exception IOException
63: * If an error occurs creating the JarOutputStream
64: */
65: @SuppressWarnings("unused")
66: public JarOutputStream(OutputStream os) throws IOException {
67: super (os);
68: }
69:
70: /**
71: * Writes the specified entry to the underlying stream. The previous entry
72: * is closed if it is still open.
73: *
74: *
75: * @param ze
76: * The ZipEntry to write
77: * @exception IOException
78: * If an error occurs writing the entry
79: */
80: @Override
81: public void putNextEntry(ZipEntry ze) throws IOException {
82: super.putNextEntry(ze);
83: }
84: }
|