< prev index next >

src/share/classes/com/sun/java/util/jar/pack/PropMap.java

Print this page
rev 1378 : 7003227: (pack200) intermittent failures compiling pack200
Reviewed-by: jjg
rev 1380 : 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
7006704: (pack200) add missing file for 6990106
Reviewed-by: mduigou, briangoetz
rev 1381 : 7060849: Eliminate pack200 build warnings
7069870: Parts of the JDK erroneously rely on generic array initializers with diamond
Reviewed-by: ksrini, jjg, mcimadamore
Contributed-by: alexandre.boulgakov@oracle.com
rev 1442 : 8164181: Remove @Override annotation on interfaces added by 2016/07 security fixes
Reviewed-by: omajid

*** 1,7 **** /* ! * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 23,82 **** * questions. */ package com.sun.java.util.jar.pack; - import java.util.*; - import java.util.jar.*; - import java.util.jar.Pack200; - import java.util.zip.*; - import java.io.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; /** * Control block for publishing Pack200 options to the other classes. */ ! class PropMap extends TreeMap { ! ArrayList _listeners = new ArrayList(1); void addListener(PropertyChangeListener listener) { ! _listeners.add(listener); } void removeListener(PropertyChangeListener listener) { ! _listeners.remove(listener); } ! void addListeners(ArrayList listeners) { ! _listeners.addAll(listeners); } ! void removeListeners(ArrayList listeners) { ! _listeners.removeAll(listeners); } // Override: ! public Object put(Object key, Object value) { ! Object oldValue = super.put(key, value); ! if (value != oldValue && _listeners.size() > 0) { // Post the property change event. PropertyChangeEvent event = ! new PropertyChangeEvent(this, (String) key, oldValue, value); ! for (Iterator i = _listeners.iterator(); i.hasNext(); ) { ! PropertyChangeListener listener = ! (PropertyChangeListener) i.next(); listener.propertyChange(event); } } return oldValue; } // All this other stuff is private to the current package. // Outide clients of Pack200 do not need to use it; they can // get by with generic SortedMap functionality. ! private static Map defaultProps; static { Properties props = new Properties(); // Allow implementation selected via -Dpack.disable.native=true props.put(Utils.DEBUG_DISABLE_NATIVE, --- 23,93 ---- * questions. */ package com.sun.java.util.jar.pack; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; + import java.io.BufferedInputStream; + import java.io.IOException; + import java.io.InputStream; + import java.io.PrintStream; + import java.io.PrintWriter; + import java.util.ArrayList; + import java.util.Collection; + import java.util.Comparator; + import java.util.HashMap; + import java.util.List; + import java.util.Map; + import java.util.Properties; + import java.util.Set; + import java.util.SortedMap; + import java.util.TreeMap; + import java.util.jar.Pack200; /** * Control block for publishing Pack200 options to the other classes. */ ! ! final class PropMap implements SortedMap<String, String> { ! private final TreeMap<String, String> theMap = new TreeMap<String, String>();; ! private final List<PropertyChangeListener> listenerList = new ArrayList<PropertyChangeListener>(1); void addListener(PropertyChangeListener listener) { ! listenerList.add(listener); } void removeListener(PropertyChangeListener listener) { ! listenerList.remove(listener); } ! void addListeners(ArrayList<PropertyChangeListener> listeners) { ! listenerList.addAll(listeners); } ! void removeListeners(ArrayList<PropertyChangeListener> listeners) { ! listenerList.removeAll(listeners); } // Override: ! public String put(String key, String value) { ! String oldValue = theMap.put(key, value); ! if (value != oldValue && !listenerList.isEmpty()) { // Post the property change event. PropertyChangeEvent event = ! new PropertyChangeEvent(this, key, oldValue, value); ! for (PropertyChangeListener listener : listenerList) { listener.propertyChange(event); } } return oldValue; } // All this other stuff is private to the current package. // Outide clients of Pack200 do not need to use it; they can // get by with generic SortedMap functionality. ! private static Map<String, String> defaultProps; static { Properties props = new Properties(); // Allow implementation selected via -Dpack.disable.native=true props.put(Utils.DEBUG_DISABLE_NATIVE,
*** 109,172 **** props.put(Pack200.Packer.EFFORT, "5"); // Define certain attribute layouts by default. // Do this after the previous props are put in place, // to allow override if necessary. try { String propFile = "intrinsic.properties"; ! InputStream propStr = PackerImpl.class.getResourceAsStream(propFile); props.load(new BufferedInputStream(propStr)); ! propStr.close(); ! for (Iterator i = props.entrySet().iterator(); i.hasNext(); ) { ! Map.Entry e = (Map.Entry) i.next(); String key = (String) e.getKey(); String val = (String) e.getValue(); if (key.startsWith("attribute.")) { e.setValue(Attribute.normalizeLayoutString(val)); } } } catch (IOException ee) { throw new RuntimeException(ee); } ! defaultProps = (new HashMap(props)); // shrink to fit } PropMap() { ! putAll(defaultProps); } // Return a view of this map which includes only properties // that begin with the given prefix. This is easy because // the map is sorted, and has a subMap accessor. ! SortedMap prefixMap(String prefix) { int len = prefix.length(); if (len == 0) return this; char nextch = (char)(prefix.charAt(len-1) + 1); String limit = prefix.substring(0, len-1)+nextch; //System.out.println(prefix+" => "+subMap(prefix, limit)); return subMap(prefix, limit); } String getProperty(String s) { ! return (String) get(s); } String getProperty(String s, String defaultVal) { String val = getProperty(s); if (val == null) return defaultVal; return val; } String setProperty(String s, String val) { ! return (String) put(s, val); } // Get sequence of props for "prefix", and "prefix.*". ! List getProperties(String prefix) { ! Collection values = prefixMap(prefix).values(); ! ArrayList res = new ArrayList(values.size()); res.addAll(values); while (res.remove(null)); return res; } --- 120,190 ---- props.put(Pack200.Packer.EFFORT, "5"); // Define certain attribute layouts by default. // Do this after the previous props are put in place, // to allow override if necessary. + InputStream propStr = null; try { String propFile = "intrinsic.properties"; ! propStr = PackerImpl.class.getResourceAsStream(propFile); props.load(new BufferedInputStream(propStr)); ! for (Map.Entry<Object, Object> e : props.entrySet()) { String key = (String) e.getKey(); String val = (String) e.getValue(); if (key.startsWith("attribute.")) { e.setValue(Attribute.normalizeLayoutString(val)); } } } catch (IOException ee) { throw new RuntimeException(ee); + } finally { + try { + if (propStr != null) { + propStr.close(); + } + } catch (IOException ignore) {} } ! @SuppressWarnings({"unchecked", "rawtypes"}) ! HashMap<String, String> temp = new HashMap(props); // shrink to fit ! defaultProps = temp; } PropMap() { ! theMap.putAll(defaultProps); } // Return a view of this map which includes only properties // that begin with the given prefix. This is easy because // the map is sorted, and has a subMap accessor. ! SortedMap<String, String> prefixMap(String prefix) { int len = prefix.length(); if (len == 0) return this; char nextch = (char)(prefix.charAt(len-1) + 1); String limit = prefix.substring(0, len-1)+nextch; //System.out.println(prefix+" => "+subMap(prefix, limit)); return subMap(prefix, limit); } String getProperty(String s) { ! return get(s); } String getProperty(String s, String defaultVal) { String val = getProperty(s); if (val == null) return defaultVal; return val; } String setProperty(String s, String val) { ! return put(s, val); } // Get sequence of props for "prefix", and "prefix.*". ! List<String> getProperties(String prefix) { ! Collection<String> values = prefixMap(prefix).values(); ! List<String> res = new ArrayList<String>(values.size()); res.addAll(values); while (res.remove(null)); return res; }
*** 226,239 **** list(outw); outw.flush(); } void list(PrintWriter out) { out.println("#"+Utils.PACK_ZIP_ARCHIVE_MARKER_COMMENT+"["); ! Set defaults = defaultProps.entrySet(); ! for (Iterator i = entrySet().iterator(); i.hasNext(); ) { ! Map.Entry e = (Map.Entry) i.next(); if (defaults.contains(e)) continue; out.println(" " + e.getKey() + " = " + e.getValue()); } out.println("#]"); } } --- 244,324 ---- list(outw); outw.flush(); } void list(PrintWriter out) { out.println("#"+Utils.PACK_ZIP_ARCHIVE_MARKER_COMMENT+"["); ! Set<Map.Entry<String, String>> defaults = defaultProps.entrySet(); ! for (Map.Entry<String, String> e : theMap.entrySet()) { if (defaults.contains(e)) continue; out.println(" " + e.getKey() + " = " + e.getValue()); } out.println("#]"); } + + public int size() { + return theMap.size(); + } + + public boolean isEmpty() { + return theMap.isEmpty(); + } + + public boolean containsKey(Object key) { + return theMap.containsKey(key); + } + + public boolean containsValue(Object value) { + return theMap.containsValue(value); + } + + public String get(Object key) { + return theMap.get(key); + } + + public String remove(Object key) { + return theMap.remove(key); + } + + public void putAll(Map<? extends String, ? extends String> m) { + theMap.putAll(m); + } + + public void clear() { + theMap.clear(); + } + + public Set<String> keySet() { + return theMap.keySet(); + } + + public Collection<String> values() { + return theMap.values(); + } + + public Set<Map.Entry<String, String>> entrySet() { + return theMap.entrySet(); + } + + public Comparator<? super String> comparator() { + return theMap.comparator(); + } + + public SortedMap<String, String> subMap(String fromKey, String toKey) { + return theMap.subMap(fromKey, toKey); + } + + public SortedMap<String, String> headMap(String toKey) { + return theMap.headMap(toKey); + } + + public SortedMap<String, String> tailMap(String fromKey) { + return theMap.tailMap(fromKey); + } + + public String firstKey() { + return theMap.firstKey(); + } + + public String lastKey() { + return theMap.lastKey(); + } }
< prev index next >