< prev index next >

src/java.base/share/classes/sun/net/www/HeaderParser.java

Print this page
rev 10947 : 8055723: Replace concat String to append in StringBuilder parameters


 203             return index<nkeys;
 204         }
 205         public String next () {
 206             return tab[index++][returnsValue?1:0];
 207         }
 208         public void remove () {
 209             throw new UnsupportedOperationException ("remove not supported");
 210         }
 211     }
 212 
 213     public Iterator<String> keys () {
 214         return new ParserIterator (false);
 215     }
 216 
 217     public Iterator<String> values () {
 218         return new ParserIterator (true);
 219     }
 220 
 221     public String toString () {
 222         Iterator<String> k = keys();
 223         StringBuffer sbuf = new StringBuffer();
 224         sbuf.append ("{size="+asize+" nkeys="+nkeys+" ");

 225         for (int i=0; k.hasNext(); i++) {
 226             String key = k.next();
 227             String val = findValue (i);
 228             if (val != null && "".equals (val)) {
 229                 val = null;
 230             }
 231             sbuf.append (" {"+key+(val==null?"":","+val)+"}");

 232             if (k.hasNext()) {
 233                 sbuf.append (",");
 234             }
 235         }
 236         sbuf.append (" }");
 237         return new String (sbuf);
 238     }
 239 
 240     public int findInt(String k, int Default) {
 241         try {
 242             return Integer.parseInt(findValue(k, String.valueOf(Default)));
 243         } catch (Throwable t) {
 244             return Default;
 245         }
 246     }
 247     /*
 248     public static void main(String[] a) throws Exception {
 249         System.out.print("enter line to parse> ");
 250         System.out.flush();
 251         DataInputStream dis = new DataInputStream(System.in);
 252         String line = dis.readLine();
 253         HeaderParser p = new HeaderParser(line);
 254         for (int i = 0; i < asize; ++i) {
 255             if (p.findKey(i) == null) break;
 256             String v = p.findValue(i);
 257             System.out.println(i + ") " +p.findKey(i) + "="+v);


 203             return index<nkeys;
 204         }
 205         public String next () {
 206             return tab[index++][returnsValue?1:0];
 207         }
 208         public void remove () {
 209             throw new UnsupportedOperationException ("remove not supported");
 210         }
 211     }
 212 
 213     public Iterator<String> keys () {
 214         return new ParserIterator (false);
 215     }
 216 
 217     public Iterator<String> values () {
 218         return new ParserIterator (true);
 219     }
 220 
 221     public String toString () {
 222         Iterator<String> k = keys();
 223         StringBuilder sb = new StringBuilder();
 224         sb.append("{size=").append(asize).append(" nkeys=").append(nkeys)
 225                 .append(' ');
 226         for (int i=0; k.hasNext(); i++) {
 227             String key = k.next();
 228             String val = findValue (i);
 229             if (val != null && "".equals (val)) {
 230                 val = null;
 231             }
 232             sb.append(" {").append(key).append(val == null ? "" : "," + val)
 233                     .append('}');
 234             if (k.hasNext()) {
 235                 sb.append (',');
 236             }
 237         }
 238         sb.append (" }");
 239         return sb.toString();
 240     }
 241 
 242     public int findInt(String k, int Default) {
 243         try {
 244             return Integer.parseInt(findValue(k, String.valueOf(Default)));
 245         } catch (Throwable t) {
 246             return Default;
 247         }
 248     }
 249     /*
 250     public static void main(String[] a) throws Exception {
 251         System.out.print("enter line to parse> ");
 252         System.out.flush();
 253         DataInputStream dis = new DataInputStream(System.in);
 254         String line = dis.readLine();
 255         HeaderParser p = new HeaderParser(line);
 256         for (int i = 0; i < asize; ++i) {
 257             if (p.findKey(i) == null) break;
 258             String v = p.findValue(i);
 259             System.out.println(i + ") " +p.findKey(i) + "="+v);
< prev index next >