src/java.base/share/classes/com/sun/java/util/jar/pack/PropMap.java
author henryjen
Fri, 15 Jun 2018 17:34:01 -0700
changeset 50603 95c0644a1c47
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199871: Deprecate pack200 and unpack200 tools Reviewed-by: mchung, psandoz, abuckley
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
32850
59bcc3c351e6 8073187: Unexpected side effect in Pack200
ksrini
parents: 25859
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.util.jar.pack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
7192
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    28
import java.io.IOException;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    29
import java.io.InputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    30
import java.io.PrintStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    31
import java.io.PrintWriter;
45011
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    32
import java.security.AccessController;
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    33
import java.security.PrivilegedAction;
7192
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    34
import java.util.ArrayList;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    35
import java.util.Collection;
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
    36
import java.util.Comparator;
7192
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    37
import java.util.HashMap;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    38
import java.util.List;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    39
import java.util.Map;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    40
import java.util.Properties;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    41
import java.util.Set;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    42
import java.util.SortedMap;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    43
import java.util.TreeMap;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6322
diff changeset
    44
import java.util.jar.Pack200;
14774
4e298ffae1c7 8004874: Reduce dependency on java.beans to only add/removePropertyChangeListener
alanb
parents: 12857
diff changeset
    45
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Control block for publishing Pack200 options to the other classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
    49
50603
95c0644a1c47 8199871: Deprecate pack200 and unpack200 tools
henryjen
parents: 47216
diff changeset
    50
@SuppressWarnings({"removal"})
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
    51
final class PropMap implements SortedMap<String, String>  {
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
    52
    private final TreeMap<String, String> theMap = new TreeMap<>();;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // Override:
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
    55
    public String put(String key, String value) {
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
    56
        String oldValue = theMap.put(key, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // All this other stuff is private to the current package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // Outide clients of Pack200 do not need to use it; they can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // get by with generic SortedMap functionality.
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
    63
    private static Map<String, String> defaultProps;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        // Allow implementation selected via -Dpack.disable.native=true
45011
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    68
        String propValue = getPropertyValue(Utils.DEBUG_DISABLE_NATIVE, "false");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        props.put(Utils.DEBUG_DISABLE_NATIVE,
45011
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    70
                  String.valueOf(Boolean.parseBoolean(propValue)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        // Set the DEBUG_VERBOSE from system
45011
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    73
        int verbose = 0;
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    74
        try {
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    75
            verbose = Integer.decode(getPropertyValue(Utils.DEBUG_VERBOSE, "0"));
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    76
        } catch (NumberFormatException e) {
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    77
        }
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    78
        props.put(Utils.DEBUG_VERBOSE, String.valueOf(verbose));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
5799
e0089b2436a4 6575373: Error verifying signatures of pack200 files in some cases
ksrini
parents: 5506
diff changeset
    80
        // The segment size is unlimited
6322
0a20892f9af6 6969063: (pack200) The default value of Pack200.Packer.SEGMENT_LIMIT property is empty string instead of -1
ksrini
parents: 5799
diff changeset
    81
        props.put(Pack200.Packer.SEGMENT_LIMIT, "-1");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        // Preserve file ordering by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        props.put(Pack200.Packer.KEEP_FILE_ORDER, Pack200.Packer.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // Preserve all modification times by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        props.put(Pack200.Packer.MODIFICATION_TIME, Pack200.Packer.KEEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // Preserve deflation hints by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        props.put(Pack200.Packer.DEFLATE_HINT, Pack200.Packer.KEEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // Pass through files with unrecognized attributes by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        props.put(Pack200.Packer.UNKNOWN_ATTRIBUTE, Pack200.Packer.PASS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 14774
diff changeset
    95
        // Pass through files with unrecognized format by default, also
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 14774
diff changeset
    96
        // allow system property to be set
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 14774
diff changeset
    97
        props.put(Utils.CLASS_FORMAT_ERROR,
45011
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
    98
                  getPropertyValue(Utils.CLASS_FORMAT_ERROR, Pack200.Packer.PASS));
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 14774
diff changeset
    99
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // Default effort is 5, midway between 1 and 9.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        props.put(Pack200.Packer.EFFORT, "5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // Define certain attribute layouts by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // Do this after the previous props are put in place,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // to allow override if necessary.
8803
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   106
        String propFile = "intrinsic.properties";
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   107
45011
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   108
        PrivilegedAction<InputStream> pa =
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   109
            () -> PackerImpl.class.getResourceAsStream(propFile);
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   110
        try (InputStream propStr = AccessController.doPrivileged(pa)) {
8803
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   111
            if (propStr == null) {
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   112
                throw new RuntimeException(propFile + " cannot be loaded");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
8803
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   114
            props.load(propStr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new RuntimeException(ee);
8803
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   117
        }
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   118
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   119
        for (Map.Entry<Object, Object> e : props.entrySet()) {
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   120
            String key = (String) e.getKey();
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   121
            String val = (String) e.getValue();
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   122
            if (key.startsWith("attribute.")) {
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   123
                e.setValue(Attribute.normalizeLayoutString(val));
b3f57bfca459 7022382: convert pack200 library code to use try-with-resources
smarks
parents: 7795
diff changeset
   124
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   127
        @SuppressWarnings({"unchecked", "rawtypes"})
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   128
        HashMap<String, String> temp = new HashMap(props);  // shrink to fit
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   129
        defaultProps = temp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
45011
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   132
    private static String getPropertyValue(String key, String defaultValue) {
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   133
        PrivilegedAction<String> pa = () -> System.getProperty(key);
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   134
        String s = AccessController.doPrivileged(pa);
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   135
        return s != null ? s : defaultValue;
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   136
    }
d47d698f27f6 8179645: java.util.jar.Packer.newPacker and newUnpacker fails when running with security manager
mchung
parents: 32850
diff changeset
   137
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    PropMap() {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   139
        theMap.putAll(defaultProps);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // Return a view of this map which includes only properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    // that begin with the given prefix.  This is easy because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    // the map is sorted, and has a subMap accessor.
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   145
    SortedMap<String, String> prefixMap(String prefix) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        int len = prefix.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (len == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        char nextch = (char)(prefix.charAt(len-1) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        String limit = prefix.substring(0, len-1)+nextch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        //System.out.println(prefix+" => "+subMap(prefix, limit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return subMap(prefix, limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    String getProperty(String s) {
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   156
        return get(s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    String getProperty(String s, String defaultVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        String val = getProperty(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (val == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return defaultVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    String setProperty(String s, String val) {
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   165
        return put(s, val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    // Get sequence of props for "prefix", and "prefix.*".
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   169
    List<String> getProperties(String prefix) {
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   170
        Collection<String> values = prefixMap(prefix).values();
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   171
        List<String> res = new ArrayList<>(values.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        res.addAll(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        while (res.remove(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private boolean toBoolean(String val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return Boolean.valueOf(val).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    boolean getBoolean(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return toBoolean(getProperty(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    boolean setBoolean(String s, boolean val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return toBoolean(setProperty(s, String.valueOf(val)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    int toInteger(String val) {
12857
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   187
        return toInteger(val, 0);
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   188
    }
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   189
    int toInteger(String val, int def) {
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   190
        if (val == null)  return def;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (Pack200.Packer.TRUE.equals(val))   return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (Pack200.Packer.FALSE.equals(val))  return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return Integer.parseInt(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
12857
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   195
    int getInteger(String s, int def) {
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   196
        return toInteger(getProperty(s), def);
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   197
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    int getInteger(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return toInteger(getProperty(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    int setInteger(String s, int val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return toInteger(setProperty(s, String.valueOf(val)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    long toLong(String val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return val == null ? 0 : Long.parseLong(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } catch (java.lang.NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            throw new IllegalArgumentException("Invalid value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    long getLong(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return toLong(getProperty(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    long setLong(String s, long val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return toLong(setProperty(s, String.valueOf(val)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    int getTime(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        String sval = getProperty(s, "0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (Utils.NOW.equals(sval)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return (int)((System.currentTimeMillis()+500)/1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        long lval = toLong(sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        final long recentSecondCount = 1000000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (lval < recentSecondCount*10 && !"0".equals(sval))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            Utils.log.warning("Supplied modtime appears to be seconds rather than milliseconds: "+sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return (int)((lval+500)/1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    void list(PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        PrintWriter outw = new PrintWriter(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        list(outw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        outw.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    void list(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        out.println("#"+Utils.PACK_ZIP_ARCHIVE_MARKER_COMMENT+"[");
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   240
        Set<Map.Entry<String, String>> defaults = defaultProps.entrySet();
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   241
        for (Map.Entry<String, String> e : theMap.entrySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (defaults.contains(e))  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            out.println("  " + e.getKey() + " = " + e.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        out.println("#]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   247
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   248
    @Override
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   249
    public int size() {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   250
        return theMap.size();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   251
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   252
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   253
    @Override
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   254
    public boolean isEmpty() {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   255
        return theMap.isEmpty();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   256
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   257
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   258
    @Override
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   259
    public boolean containsKey(Object key) {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   260
        return theMap.containsKey(key);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   261
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   262
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   263
    @Override
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   264
    public boolean containsValue(Object value) {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   265
        return theMap.containsValue(value);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   266
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   267
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   268
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   269
    public String get(Object key) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   270
        return theMap.get(key);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   271
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   272
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   273
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   274
    public String remove(Object key) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   275
       return theMap.remove(key);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   276
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   277
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   278
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   279
    public void putAll(Map<? extends String, ? extends String> m) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   280
       theMap.putAll(m);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   281
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   282
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   283
    @Override
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   284
    public void clear() {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   285
        theMap.clear();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   286
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   287
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   288
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   289
    public Set<String> keySet() {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   290
       return theMap.keySet();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   291
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   292
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   293
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   294
    public Collection<String> values() {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   295
       return theMap.values();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   296
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   297
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   298
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   299
    public Set<Map.Entry<String, String>> entrySet() {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   300
        return theMap.entrySet();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   301
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   302
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   303
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   304
    public Comparator<? super String> comparator() {
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   305
        return theMap.comparator();
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   306
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   307
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   308
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   309
    public SortedMap<String, String> subMap(String fromKey, String toKey) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   310
        return theMap.subMap(fromKey, toKey);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   311
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   312
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   313
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   314
    public SortedMap<String, String> headMap(String toKey) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   315
        return theMap.headMap(toKey);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   316
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   317
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   318
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   319
    public SortedMap<String, String> tailMap(String fromKey) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   320
        return theMap.tailMap(fromKey);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   321
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   322
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   323
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   324
    public String firstKey() {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   325
        return theMap.firstKey();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   326
    }
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   327
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   328
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 9035
diff changeset
   329
    public String lastKey() {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   330
       return theMap.lastKey();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   331
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
}