cookieparse.java

来自「< 网络机器人java编程指南>>的配套源程序」· Java 代码 · 共 94 行

JAVA
94
字号
package com.heaton.bot;/** * This class is used to parse cookies that are transmitted * with the HTTP headers. * * Copyright 2001-2003 by Jeff Heaton (http://www.jeffheaton.com) * * @author Jeff Heaton * @version 1.2 */public class CookieParse extends Parse {  /**   * Special version of the parseAttribute method.   */  public void parseAttributeValue()  {    eatWhiteSpace();    if ( eof() )      return;    if ( source.charAt(idx)=='=' ) {      idx++;      eatWhiteSpace();      if ( (source.charAt(idx)=='\'') ||           (source.charAt(idx)=='\"') ) {        parseDelim = source.charAt(idx);        idx++;        while ( source.charAt(idx)!=parseDelim ) {          parseValue+=source.charAt(idx);          idx++;        }        idx++;      } else {        while ( !eof() && (source.charAt(idx)!=';') ) {          parseValue+=source.charAt(idx);          idx++;        }      }      eatWhiteSpace();    }  }  /**   * Called to parse this cookie.   *   * @return The return value is unused.   */  public boolean get()  {    // get the attributes    while ( !eof() ) {      parseName="";      parseValue="";      parseAttributeName();      if ( !eof() && (source.charAt(idx)==';') ) {        addAttribute();        break;      }      // get the value(if any)      parseAttributeValue();      addAttribute();      // move forward to the ; if there is one      eatWhiteSpace();      while ( !eof() ) {        if ( source.charAt(idx++)==';' )          break;      }    }    idx++;    return false;  }  /**   * Convert this cookie to a string to be sent as   * an HTTP header.   *   * @return This cookie as a string.   */  public String toString()  {    String str;    str = get(0).getName();    str+= "=";    str+= get(0).getValue();    return str;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?