FileDocCategorySizeDatePackage
SafeBufferedReader.javaAPI DocExample954Sun Dec 12 10:51:12 GMT 2004com.macfaq.io

SafeBufferedReader

public class SafeBufferedReader extends BufferedReader

Fields Summary
private boolean
lookingForLineFeed
Constructors Summary
public SafeBufferedReader(Reader in)

    this(in, 1024);
  
public SafeBufferedReader(Reader in, int bufferSize)

    super(in, bufferSize);
  
Methods Summary
public java.lang.StringreadLine()

  
       
    StringBuffer sb = new StringBuffer("");
    while (true) {
      int c = this.read();
      if (c == -1) { // end of stream
        if (sb.equals("")) return null;
        return sb.toString();
      }
      else if (c == '\n") {
        if (lookingForLineFeed) {
          lookingForLineFeed = false;
          continue;
        }
        else {
          return sb.toString();
        }
      }
      else if (c == '\r") {
        lookingForLineFeed = true;
        return sb.toString();
      }
      else {
        lookingForLineFeed = false;
        sb.append((char) c);
      }
    }