StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
  void handleSetCookie(String text)  {    CookieManager cookieManager = connection.getCookieManager();    if (cookieManager == null)      {        return;      }    String name = null;    String value = null;    String comment = null;    String domain = connection.getHostName();    String path = this.path;    int lsi = path.lastIndexOf('/');    if (lsi != -1)      {        path = path.substring(0, lsi);      }    boolean secure = false;    Date expires = null;    int len = text.length();    String attr = null;    StringBuffer buf = new StringBuffer();    boolean inQuote = false;    for (int i = 0; i <= len; i++)      {        char c =(i == len) ? '\u0000' : text.charAt(i);        if (c == '"')          {            inQuote = !inQuote;          }        else if (!inQuote)          {            if (c == '=' && attr == null)              {                attr = buf.toString().trim();                buf.setLength(0);              }            else if (c == ';' || i == len || c == ',')              {                String val = unquote(buf.toString().trim());                if (name == null)                  {                    name = attr;                    value = val;                  }                else if ("Comment".equalsIgnoreCase(attr))                  {                    comment = val;                  }                else if ("Domain".equalsIgnoreCase(attr))                  {                    domain = val;                  }                else if ("Path".equalsIgnoreCase(attr))                  {                    path = val;                  }                else if ("Secure".equalsIgnoreCase(val))                  {                    secure = true;                  }                else if ("Max-Age".equalsIgnoreCase(attr))                  {                    int delta = Integer.parseInt(val);                    Calendar cal = Calendar.getInstance();                    cal.setTimeInMillis(System.currentTimeMillis());                    cal.add(Calendar.SECOND, delta);                    expires = cal.getTime();                  }                else if ("Expires".equalsIgnoreCase(attr))                  {                    DateFormat dateFormat = new HTTPDateFormat();                    try                      {                        expires = dateFormat.parse(val);                      }                    catch (ParseException e)                      {                        // if this isn't a valid date, it may be that                        // the value was returned unquoted; in that case, we                        // want to continue buffering the value                        buf.append(c);                        continue;                      }                  }                attr = null;                buf.setLength(0);                // case EOL                if (i == len || c == ',')                  {                    Cookie cookie = new Cookie(name, value, comment, domain,                                               path, secure, expires);                    cookieManager.setCookie(cookie);                  }                if (c == ',')                  {                    // Reset cookie fields                    name = null;                    value = null;                    comment = null;                    domain = connection.getHostName();                    path = this.path;                    if (lsi != -1)                      {                        path = path.substring(0, lsi);                      }                    secure = false;                    expires = null;                  }              }            else              {                buf.append(c);              }          }        else          {            buf.append(c);          }      }  }