jdk/src/share/classes/sun/net/www/MessageHeader.java
changeset 10596 39b3a979e600
parent 7668 d4a77089c587
child 14766 1f22dd6f2658
equal deleted inserted replaced
10595:c5be3e19fbab 10596:39b3a979e600
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    33 import java.util.Collections;
    33 import java.util.Collections;
    34 import java.util.Map;
    34 import java.util.Map;
    35 import java.util.HashMap;
    35 import java.util.HashMap;
    36 import java.util.List;
    36 import java.util.List;
    37 import java.util.ArrayList;
    37 import java.util.ArrayList;
    38 import java.util.Set;
       
    39 import java.util.Iterator;
    38 import java.util.Iterator;
    40 import java.util.NoSuchElementException;
    39 import java.util.NoSuchElementException;
    41 
    40 
    42 /** An RFC 844 or MIME message header.  Includes methods
    41 /** An RFC 844 or MIME message header.  Includes methods
    43     for parsing headers from incoming streams, fetching
    42     for parsing headers from incoming streams, fetching
   197 
   196 
   198     public synchronized Map<String, List<String>> getHeaders(String[] excludeList) {
   197     public synchronized Map<String, List<String>> getHeaders(String[] excludeList) {
   199         return filterAndAddHeaders(excludeList, null);
   198         return filterAndAddHeaders(excludeList, null);
   200     }
   199     }
   201 
   200 
   202     public synchronized Map<String, List<String>> filterAndAddHeaders(String[] excludeList, Map<String, List<String>>  include) {
   201     public synchronized Map<String, List<String>> filterAndAddHeaders(
       
   202             String[] excludeList, Map<String, List<String>>  include) {
   203         boolean skipIt = false;
   203         boolean skipIt = false;
   204         Map<String, List<String>> m = new HashMap<String, List<String>>();
   204         Map<String, List<String>> m = new HashMap<String, List<String>>();
   205         for (int i = nkeys; --i >= 0;) {
   205         for (int i = nkeys; --i >= 0;) {
   206             if (excludeList != null) {
   206             if (excludeList != null) {
   207                 // check if the key is in the excludeList.
   207                 // check if the key is in the excludeList.
   226                 skipIt = false;
   226                 skipIt = false;
   227             }
   227             }
   228         }
   228         }
   229 
   229 
   230         if (include != null) {
   230         if (include != null) {
   231             Iterator entries = include.entrySet().iterator();
   231                 for (Map.Entry<String,List<String>> entry: include.entrySet()) {
   232             while (entries.hasNext()) {
   232                 List<String> l = m.get(entry.getKey());
   233                 Map.Entry entry = (Map.Entry)entries.next();
       
   234                 List l = (List)m.get(entry.getKey());
       
   235                 if (l == null) {
   233                 if (l == null) {
   236                     l = new ArrayList();
   234                     l = new ArrayList<String>();
   237                     m.put((String)entry.getKey(), l);
   235                     m.put(entry.getKey(), l);
   238                 }
   236                 }
   239                 l.add(entry.getValue());
   237                 l.addAll(entry.getValue());
   240             }
   238             }
   241         }
   239         }
   242 
   240 
   243         for (String key : m.keySet()) {
   241         for (String key : m.keySet()) {
   244             m.put(key, Collections.unmodifiableList(m.get(key)));
   242             m.put(key, Collections.unmodifiableList(m.get(key)));
   398         }
   396         }
   399         mergeHeader(is);
   397         mergeHeader(is);
   400     }
   398     }
   401 
   399 
   402     /** Parse and merge a MIME header from an input stream. */
   400     /** Parse and merge a MIME header from an input stream. */
       
   401     @SuppressWarnings("fallthrough")
   403     public void mergeHeader(InputStream is) throws java.io.IOException {
   402     public void mergeHeader(InputStream is) throws java.io.IOException {
   404         if (is == null)
   403         if (is == null)
   405             return;
   404             return;
   406         char s[] = new char[10];
   405         char s[] = new char[10];
   407         int firstc = is.read();
   406         int firstc = is.read();
   419                             keyend = len;
   418                             keyend = len;
   420                         inKey = false;
   419                         inKey = false;
   421                         break;
   420                         break;
   422                       case '\t':
   421                       case '\t':
   423                         c = ' ';
   422                         c = ' ';
       
   423                       /*fall through*/
   424                       case ' ':
   424                       case ' ':
   425                         inKey = false;
   425                         inKey = false;
   426                         break;
   426                         break;
   427                       case '\r':
   427                       case '\r':
   428                       case '\n':
   428                       case '\n':