< prev index next >

src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java

Print this page




2405      * Input cache.  This is much faster than calling down to a synchronized
2406      * method of BufferedReader for each byte.  Measurements done 5/30/97
2407      * show that there's no point in having a bigger buffer:  Increasing
2408      * the buffer to 8192 had no measurable impact for a program discarding
2409      * one character at a time (reading from an http URL to a local machine).
2410      * NOTE: If the current encoding is bogus, and we read too much
2411      * (past the content-type) we may suffer a MalformedInputException. For
2412      * this reason the initial size is 1 and when the body is encountered the
2413      * size is adjusted to 256.
2414      */
2415     private char buf[] = new char[1];
2416     private int pos;
2417     private int len;
2418     /*
2419         tracks position relative to the beginning of the
2420         document.
2421     */
2422     private int currentPosition;
2423 
2424 
2425     private final int readCh() throws IOException {
2426 
2427         if (pos >= len) {
2428 
2429             // This loop allows us to ignore interrupts if the flag
2430             // says so
2431             for (;;) {
2432                 try {
2433                     len = in.read(buf);
2434                     break;
2435                 } catch (InterruptedIOException ex) {
2436                     throw ex;
2437                 }
2438             }
2439 
2440             if (len <= 0) {
2441                 return -1;      // eof
2442             }
2443             pos = 0;
2444         }
2445         ++currentPosition;


2405      * Input cache.  This is much faster than calling down to a synchronized
2406      * method of BufferedReader for each byte.  Measurements done 5/30/97
2407      * show that there's no point in having a bigger buffer:  Increasing
2408      * the buffer to 8192 had no measurable impact for a program discarding
2409      * one character at a time (reading from an http URL to a local machine).
2410      * NOTE: If the current encoding is bogus, and we read too much
2411      * (past the content-type) we may suffer a MalformedInputException. For
2412      * this reason the initial size is 1 and when the body is encountered the
2413      * size is adjusted to 256.
2414      */
2415     private char buf[] = new char[1];
2416     private int pos;
2417     private int len;
2418     /*
2419         tracks position relative to the beginning of the
2420         document.
2421     */
2422     private int currentPosition;
2423 
2424 
2425     private int readCh() throws IOException {
2426 
2427         if (pos >= len) {
2428 
2429             // This loop allows us to ignore interrupts if the flag
2430             // says so
2431             for (;;) {
2432                 try {
2433                     len = in.read(buf);
2434                     break;
2435                 } catch (InterruptedIOException ex) {
2436                     throw ex;
2437                 }
2438             }
2439 
2440             if (len <= 0) {
2441                 return -1;      // eof
2442             }
2443             pos = 0;
2444         }
2445         ++currentPosition;
< prev index next >