home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-20 | 2.6 KB | 76 lines |
- /*
- * @(#)JarOutputStream.java 1.10 98/03/18
- *
- * Copyright 1997 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
- */
-
- package java.util.jar;
-
- import java.util.zip.*;
- import java.io.*;
-
- /**
- * The <code>JarOutputStream</code> class is used to write the contents
- * of a JAR file to any output stream. It extends the class
- * <code>java.util.zip.ZipOutputStream</code> with support
- * for writing an optional <code>Manifest</code> entry. The
- * <code>Manifest</code> can be used to specify meta-information about
- * the JAR file and its entries.
- *
- * @author David Connelly
- * @version 1.10, 03/18/98
- * @see Manifest
- * @see java.util.zip.ZipOutputStream
- * @since JDK1.2
- */
- public
- class JarOutputStream extends ZipOutputStream {
- /**
- * ZIP file header extra field data used to identify an executable
- * JAR file. This value must be present in the extra field data
- * header of the manifest entry to be recognized as an executable
- * JAR file with an entry point. It is automatically added when
- * the <code>Main-Class</code> manifest header is defined.
- */
- public static final byte[] EDATA_JAX = { (byte)0xFE, (byte)0xCA, (byte)0 };
-
- /**
- * Creates a new <code>JarOutputStream</code> with the specified
- * <code>Manifest</code>. The manifest is written as the first
- * entry to the output stream.
- * @param out the actual output stream
- * @param man the optional <code>Manifest</code>
- * @exception IOException if an I/O error has occurred
- */
- public JarOutputStream(OutputStream out, Manifest man) throws IOException {
- super(out);
- ZipEntry e = new ZipEntry(JarFile.MANIFEST_NAME);
- e.setComment("JAR manifest");
- Attributes attr = man.getMainAttributes();
- if (attr != null && attr.get(Attributes.Name.MAIN_CLASS) != null) {
- // If executable JAR (JAX) file then set extra field data
- e.setExtra(EDATA_JAX);
- }
- putNextEntry(e);
- man.write(new BufferedOutputStream(this));
- closeEntry();
- }
-
- /**
- * Creates a new <code>JarOutputStream</code> with default manifest.
- * @param out the actual output stream
- * @exception IOException if an I/O error has occurred
- */
- public JarOutputStream(OutputStream out) throws IOException {
- this(out, new Manifest());
- }
- }
-