Path: blob/master/src/jdk.httpserver/share/classes/sun/net/httpserver/UnmodifiableHeaders.java
41159 views
/*1* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.net.httpserver;2627import java.util.*;28import java.util.function.BiFunction;29import com.sun.net.httpserver.*;3031public class UnmodifiableHeaders extends Headers {3233private final Headers headers; // modifiable, but no reference to it escapes34private final Map<String, List<String>> map; // unmodifiable3536public UnmodifiableHeaders(Headers headers) {37var h = headers;38var unmodHeaders = new Headers();39h.forEach((k, v) -> unmodHeaders.put(k, Collections.unmodifiableList(v)));40this.map = Collections.unmodifiableMap(unmodHeaders);41this.headers = unmodHeaders;42}4344public int size() {return headers.size();}4546public boolean isEmpty() {return headers.isEmpty();}4748public boolean containsKey(Object key) { return headers.containsKey(key); }4950public boolean containsValue(Object value) { return headers.containsValue(value); }5152public List<String> get(Object key) { return headers.get(key); }5354public String getFirst(String key) { return headers.getFirst(key); }5556public List<String> put(String key, List<String> value) {57throw new UnsupportedOperationException ("unsupported operation");58}5960public void add(String key, String value) {61throw new UnsupportedOperationException ("unsupported operation");62}6364public void set(String key, String value) {65throw new UnsupportedOperationException ("unsupported operation");66}6768public List<String> remove(Object key) {69throw new UnsupportedOperationException ("unsupported operation");70}7172public void putAll(Map<? extends String,? extends List<String>> t) {73throw new UnsupportedOperationException ("unsupported operation");74}7576public void clear() {77throw new UnsupportedOperationException ("unsupported operation");78}7980public Set<String> keySet() { return map.keySet(); }8182public Collection<List<String>> values() { return map.values(); }8384/* TODO check that contents of set are not modifable : security */8586public Set<Map.Entry<String, List<String>>> entrySet() { return map.entrySet(); }8788public List<String> replace(String key, List<String> value) {89throw new UnsupportedOperationException("unsupported operation");90}9192public boolean replace(String key, List<String> oldValue, List<String> newValue) {93throw new UnsupportedOperationException ("unsupported operation");94}9596public void replaceAll(BiFunction<? super String, ? super List<String>, ? extends List<String>> function) {97throw new UnsupportedOperationException ("unsupported operation");98}99100public boolean equals(Object o) {return headers.equals(o);}101102public int hashCode() {return headers.hashCode();}103}104105106