Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. String readLine(boolean ignoreLF) throws IOException {
  2.         StringBuffer s = null;
  3.         int startChar;
  4.  
  5.         synchronized (lock) {
  6.             ensureOpen();
  7.             boolean omitLF = ignoreLF || skipLF;
  8.  
  9.         bufferLoop:
  10.             for (;;) {
  11.  
  12.                 if (nextChar >= nChars)
  13.                     fill();
  14.                 if (nextChar >= nChars) { /* EOF */
  15.                     if (s != null && s.length() > 0)
  16.                         return s.toString();
  17.                     else
  18.                         return null;
  19.                 }
  20.                 boolean eol = false;
  21.                 char c = 0;
  22.                 int i;
  23.  
  24.                 /* Skip a leftover '\n', if necessary */
  25.                 if (omitLF && (cb[nextChar] == '\n'))
  26.                     nextChar++;
  27.                 skipLF = false;
  28.                 omitLF = false;
  29.  
  30.             charLoop:
  31.                 for (i = nextChar; i < nChars; i++) {
  32.                     c = cb[i];
  33.                     if ((c == '\n') || (c == '\r')) {
  34.                         eol = true;
  35.                         break charLoop;
  36.                     }
  37.                 }
  38.  
  39.                 startChar = nextChar;
  40.                 nextChar = i;
  41.  
  42.                 if (eol) {
  43.                     String str;
  44.                     if (s == null) {
  45.                         str = new String(cb, startChar, i - startChar);
  46.                     } else {
  47.                         s.append(cb, startChar, i - startChar);
  48.                         str = s.toString();
  49.                     }
  50.                     nextChar++;
  51.                     if (c == '\r') {
  52.                         skipLF = true;
  53.                     }
  54.                     return str;
  55.                 }
  56.  
  57.                 if (s == null)
  58.                     s = new StringBuffer(defaultExpectedLineLength);
  59.                 s.append(cb, startChar, i - startChar);
  60.             }
  61.         }
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement