len = (len < MIN_LENGTH) ? MIN_LENGTH : len;
if (len == 0 || len > MAX_LENGTH) len = MAX_LENGTH;
  public String readLine()    throws IOException  {    if (eof)      {        return null;      }    do      {        if (blockReads)          {            // Use mark and reset to read chunks of bytes            final int MIN_LENGTH = 1024;            int len, pos;                        len = in.available();            len = (len < MIN_LENGTH) ? MIN_LENGTH : len;            byte[] b = new byte[len];            in.mark(len);            // Read into buffer b            len = in.read(b, 0, len);            // Handle EOF            if (len == -1)              {                eof = true;                if (buf.size() == 0)                  {                    return null;                  }                else                  {                    // We don't care about resetting buf                    return buf.toString(encoding);                  }              }            // Get index of LF in b            pos = indexOf(b, len, (byte) 0x0a);            if (pos != -1)              {                // Write pos bytes to buf                buf.write(b, 0, pos);                // Reset stream, and read pos + 1 bytes                in.reset();                pos += 1;                while (pos > 0)                  {                    len = in.read(b, 0, pos);                    pos = (len == -1) ? -1 : pos - len;                  }                // Return line                String ret = buf.toString(encoding);                buf.reset();                return ret;              }            else              {                // Append everything to buf and fall through to re-read.                buf.write(b, 0, len);              }          }        else          {            // We must use character reads in order not to read too much            // from the underlying stream.            int c = in.read();            switch (c)              {              case -1:                eof = true;                if (buf.size() == 0)                  {                    return null;                  }                // Fall through and return contents of buffer.              case 0x0a:                // LF                String ret = buf.toString(encoding);                buf.reset();                return ret;              default:                buf.write(c);              }          }      }    while (true);  }