| 31 | } |
| 32 | |
| 33 | public String readLine() throws IOException { |
| 34 | StringBuilder sb = new StringBuilder(); |
| 35 | while (true) { |
| 36 | if (position >= limit) { |
| 37 | fill(); |
| 38 | } |
| 39 | |
| 40 | if (position >= limit) { |
| 41 | return sb.length() == 0 ? null : sb.toString(); |
| 42 | } |
| 43 | |
| 44 | for (int i = position; i < limit; ++i) { |
| 45 | if(buffer[i] == '\r') { |
| 46 | sb.append(buffer, position, i - position); |
| 47 | position = i + 1; |
| 48 | if(i+1 < limit && buffer[i+1] == '\n') { |
| 49 | position = i + 2; |
| 50 | } |
| 51 | return sb.toString(); |
| 52 | } else if (buffer[i] == '\n') { |
| 53 | sb.append(buffer, position, i - position); |
| 54 | position = i + 1; |
| 55 | return sb.toString(); |
| 56 | } |
| 57 | } |
| 58 | sb.append(buffer, position, limit-position); |
| 59 | position = limit; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | public int read(char[] b, int offset, int length) throws IOException { |
| 64 | int count = 0; |