jdk/src/share/classes/sun/net/www/HeaderParser.java
author chegar
Fri, 16 Sep 2011 12:09:04 -0700
changeset 10596 39b3a979e600
parent 5506 202f599c92aa
permissions -rw-r--r--
7090158: Networking Libraries don't build with javac -Werror Summary: Minor changes to networking java files to remove warnings Reviewed-by: chegar, weijun, hawtin Contributed-by: kurchi.subhra.hazra@oracle.com, sasha_bu@hotmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
     2
 * Copyright (c) 1996, 2011, 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 sun.net.www;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/* This is useful for the nightmare of parsing multi-part HTTP/RFC822 headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * sensibly:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * From a String like: 'timeout=15, max=5'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * create an array of Strings:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * { {"timeout", "15"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   {"max", "5"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * From one like: 'Basic Realm="FuzzFace" Foo="Biz Bar Baz"'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * create one like (no quotes in literal):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * { {"basic", null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *   {"realm", "FuzzFace"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *   {"foo", "Biz Bar Baz"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * keys are converted to lower case, vals are left as is....
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Dave Brown
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class HeaderParser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /* table of key/val pairs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    String raw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    String[][] tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int nkeys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    int asize = 10; // initial size of array is 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public HeaderParser(String raw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.raw = raw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        tab = new String[asize][2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        parse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private HeaderParser () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * create a new HeaderParser from this, whose keys (and corresponding values)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * range from "start" to "end-1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public HeaderParser subsequence (int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (start == 0 && end == nkeys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (start < 0 || start >= end || end > nkeys)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            throw new IllegalArgumentException ("invalid start or end");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        HeaderParser n = new HeaderParser ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        n.tab = new String [asize][2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        n.asize = asize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        System.arraycopy (tab, start, n.tab, 0, (end-start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        n.nkeys= (end-start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private void parse() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (raw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            raw = raw.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            char[] ca = raw.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            int beg = 0, end = 0, i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            boolean inKey = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            boolean inQuote = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            int len = ca.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            while (end < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                char c = ca[end];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                if ((c == '=') && !inQuote) { // end of a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    tab[i][0] = new String(ca, beg, end-beg).toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    inKey = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    end++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    beg = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                } else if (c == '\"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    if (inQuote) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                        tab[i++][1]= new String(ca, beg, end-beg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        inQuote=false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                            end++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        } while (end < len && (ca[end] == ' ' || ca[end] == ','));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                        inKey=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                        beg=end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                        inQuote=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        end++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        beg=end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                } else if (c == ' ' || c == ',') { // end key/val, of whatever we're in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    if (inQuote) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                        end++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    } else if (inKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        tab[i++][0] = (new String(ca, beg, end-beg)).toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                        tab[i++][1] = (new String(ca, beg, end-beg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    while (end < len && (ca[end] == ' ' || ca[end] == ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                        end++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    inKey = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    beg = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    end++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                if (i == asize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    asize = asize * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    String[][] ntab = new String[asize][2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    System.arraycopy (tab, 0, ntab, 0, tab.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    tab = ntab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            // get last key/val, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (--end > beg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                if (!inKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    if (ca[end] == '\"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        tab[i++][1] = (new String(ca, beg, end-beg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                        tab[i++][1] = (new String(ca, beg, end-beg+1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    tab[i++][0] = (new String(ca, beg, end-beg+1)).toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            } else if (end == beg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                if (!inKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    if (ca[end] == '\"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                        tab[i++][1] = String.valueOf(ca[end-1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        tab[i++][1] = String.valueOf(ca[end]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    tab[i++][0] = String.valueOf(ca[end]).toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            nkeys=i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public String findKey(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (i < 0 || i > asize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return tab[i][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public String findValue(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (i < 0 || i > asize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return tab[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public String findValue(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return findValue(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public String findValue(String k, String Default) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (k == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return Default;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        k = k.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        for (int i = 0; i < asize; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (tab[i][0] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                return Default;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            } else if (k.equals(tab[i][0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                return tab[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return Default;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   195
    class ParserIterator implements Iterator<String> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        boolean returnsValue; // or key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        ParserIterator (boolean returnValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            returnsValue = returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        public boolean hasNext () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return index<nkeys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   205
        public String next () {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return tab[index++][returnsValue?1:0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        public void remove () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            throw new UnsupportedOperationException ("remove not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   213
    public Iterator<String> keys () {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return new ParserIterator (false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   217
    public Iterator<String> values () {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return new ParserIterator (true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public String toString () {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   222
        Iterator<String> k = keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        StringBuffer sbuf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        sbuf.append ("{size="+asize+" nkeys="+nkeys+" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        for (int i=0; k.hasNext(); i++) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   226
            String key = k.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            String val = findValue (i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (val != null && "".equals (val)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                val = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            sbuf.append (" {"+key+(val==null?"":","+val)+"}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            if (k.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                sbuf.append (",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        sbuf.append (" }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return new String (sbuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public int findInt(String k, int Default) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return Integer.parseInt(findValue(k, String.valueOf(Default)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return Default;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public static void main(String[] a) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        System.out.print("enter line to parse> ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        System.out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        DataInputStream dis = new DataInputStream(System.in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        String line = dis.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        HeaderParser p = new HeaderParser(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        for (int i = 0; i < asize; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if (p.findKey(i) == null) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            String v = p.findValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            System.out.println(i + ") " +p.findKey(i) + "="+v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        System.out.println("Done!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
}