home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / util / jar / JarOutputStream.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  2.6 KB  |  76 lines

  1. /*
  2.  * @(#)JarOutputStream.java    1.10 98/03/18
  3.  *
  4.  * Copyright 1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.util.jar;
  16.  
  17. import java.util.zip.*;
  18. import java.io.*;
  19.  
  20. /**
  21.  * The <code>JarOutputStream</code> class is used to write the contents
  22.  * of a JAR file to any output stream. It extends the class
  23.  * <code>java.util.zip.ZipOutputStream</code> with support
  24.  * for writing an optional <code>Manifest</code> entry. The
  25.  * <code>Manifest</code> can be used to specify meta-information about
  26.  * the JAR file and its entries.
  27.  *
  28.  * @author  David Connelly
  29.  * @version 1.10, 03/18/98
  30.  * @see        Manifest
  31.  * @see        java.util.zip.ZipOutputStream
  32.  * @since   JDK1.2
  33.  */
  34. public
  35. class JarOutputStream extends ZipOutputStream {
  36.     /**
  37.      * ZIP file header extra field data used to identify an executable
  38.      * JAR file. This value must be present in the extra field data
  39.      * header of the manifest entry to be recognized as an executable
  40.      * JAR file with an entry point. It is automatically added when
  41.      * the <code>Main-Class</code> manifest header is defined.
  42.      */
  43.     public static final byte[] EDATA_JAX = { (byte)0xFE, (byte)0xCA, (byte)0 };
  44.  
  45.     /**
  46.      * Creates a new <code>JarOutputStream</code> with the specified
  47.      * <code>Manifest</code>. The manifest is written as the first
  48.      * entry to the output stream.
  49.      * @param out the actual output stream
  50.      * @param man the optional <code>Manifest</code>
  51.      * @exception IOException if an I/O error has occurred
  52.      */
  53.     public JarOutputStream(OutputStream out, Manifest man) throws IOException {
  54.     super(out);
  55.     ZipEntry e = new ZipEntry(JarFile.MANIFEST_NAME);
  56.     e.setComment("JAR manifest");
  57.     Attributes attr = man.getMainAttributes();
  58.     if (attr != null && attr.get(Attributes.Name.MAIN_CLASS) != null) {
  59.         // If executable JAR (JAX) file then set extra field data
  60.         e.setExtra(EDATA_JAX);
  61.     }
  62.     putNextEntry(e);
  63.     man.write(new BufferedOutputStream(this));
  64.     closeEntry();
  65.     }
  66.  
  67.     /**
  68.      * Creates a new <code>JarOutputStream</code> with default manifest.
  69.      * @param out the actual output stream
  70.      * @exception IOException if an I/O error has occurred
  71.      */
  72.     public JarOutputStream(OutputStream out) throws IOException {
  73.     this(out, new Manifest());
  74.     }
  75. }
  76.