src/share/classes/java/util/jar/Manifest.java

Print this page
rev 10449 : [mq]: cds
   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.jar;
  27 

  28 import java.io.FilterInputStream;
  29 import java.io.DataOutputStream;
  30 import java.io.InputStream;
  31 import java.io.OutputStream;
  32 import java.io.IOException;
  33 import java.util.Map;
  34 import java.util.HashMap;
  35 import java.util.Iterator;
  36 
  37 /**
  38  * The Manifest class is used to maintain Manifest entry names and their
  39  * associated Attributes. There are main Manifest Attributes as well as
  40  * per-entry Attributes. For information on the Manifest format, please
  41  * see the
  42  * <a href="../../../../technotes/guides/jar/jar.html">
  43  * Manifest format specification</a>.
  44  *
  45  * @author  David Connelly
  46  * @see     Attributes
  47  * @since   1.2


  60     }
  61 
  62     /**
  63      * Constructs a new Manifest from the specified input stream.
  64      *
  65      * @param is the input stream containing manifest data
  66      * @throws IOException if an I/O error has occurred
  67      */
  68     public Manifest(InputStream is) throws IOException {
  69         read(is);
  70     }
  71 
  72     /**
  73      * Constructs a new Manifest that is a copy of the specified Manifest.
  74      *
  75      * @param man the Manifest to copy
  76      */
  77     public Manifest(Manifest man) {
  78         attr.putAll(man.getMainAttributes());
  79         entries.putAll(man.getEntries());








  80     }
  81 
  82     /**
  83      * Returns the main Attributes for the Manifest.
  84      * @return the main Attributes for the Manifest
  85      */
  86     public Attributes getMainAttributes() {
  87         return attr;
  88     }
  89 
  90     /**
  91      * Returns a Map of the entries contained in this Manifest. Each entry
  92      * is represented by a String name (key) and associated Attributes (value).
  93      * The Map permits the {@code null} key, but no entry with a null key is
  94      * created by {@link #read}, nor is such an entry written by using {@link
  95      * #write}.
  96      *
  97      * @return a Map of the entries contained in this Manifest
  98      */
  99     public Map<String,Attributes> getEntries() {


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.jar;
  27 
  28 import java.io.ByteArrayInputStream;
  29 import java.io.FilterInputStream;
  30 import java.io.DataOutputStream;
  31 import java.io.InputStream;
  32 import java.io.OutputStream;
  33 import java.io.IOException;
  34 import java.util.Map;
  35 import java.util.HashMap;
  36 import java.util.Iterator;
  37 
  38 /**
  39  * The Manifest class is used to maintain Manifest entry names and their
  40  * associated Attributes. There are main Manifest Attributes as well as
  41  * per-entry Attributes. For information on the Manifest format, please
  42  * see the
  43  * <a href="../../../../technotes/guides/jar/jar.html">
  44  * Manifest format specification</a>.
  45  *
  46  * @author  David Connelly
  47  * @see     Attributes
  48  * @since   1.2


  61     }
  62 
  63     /**
  64      * Constructs a new Manifest from the specified input stream.
  65      *
  66      * @param is the input stream containing manifest data
  67      * @throws IOException if an I/O error has occurred
  68      */
  69     public Manifest(InputStream is) throws IOException {
  70         read(is);
  71     }
  72 
  73     /**
  74      * Constructs a new Manifest that is a copy of the specified Manifest.
  75      *
  76      * @param man the Manifest to copy
  77      */
  78     public Manifest(Manifest man) {
  79         attr.putAll(man.getMainAttributes());
  80         entries.putAll(man.getEntries());
  81     }
  82 
  83     /**
  84      * Used by the VM to create a Manifest object from input bytes.
  85      */
  86     private static Manifest getManifest(byte buf[]) throws IOException {
  87         ByteArrayInputStream is = new ByteArrayInputStream(buf);
  88         return new Manifest(is);
  89     }
  90 
  91     /**
  92      * Returns the main Attributes for the Manifest.
  93      * @return the main Attributes for the Manifest
  94      */
  95     public Attributes getMainAttributes() {
  96         return attr;
  97     }
  98 
  99     /**
 100      * Returns a Map of the entries contained in this Manifest. Each entry
 101      * is represented by a String name (key) and associated Attributes (value).
 102      * The Map permits the {@code null} key, but no entry with a null key is
 103      * created by {@link #read}, nor is such an entry written by using {@link
 104      * #write}.
 105      *
 106      * @return a Map of the entries contained in this Manifest
 107      */
 108     public Map<String,Attributes> getEntries() {