126 * @param name
127 * a {@code String} specifying the name of the cookie
128 *
129 * @param value
130 * a {@code String} specifying the value of the cookie
131 *
132 * @throws IllegalArgumentException
133 * if the cookie name contains illegal characters
134 * @throws NullPointerException
135 * if {@code name} is {@code null}
136 *
137 * @see #setValue
138 * @see #setVersion
139 */
140 public HttpCookie(String name, String value) {
141 this(name, value, null /*header*/);
142 }
143
144 private HttpCookie(String name, String value, String header) {
145 name = name.trim();
146 if (name.length() == 0 || !isToken(name) || name.charAt(0) == '$') {
147 throw new IllegalArgumentException("Illegal cookie name");
148 }
149
150 this.name = name;
151 this.value = value;
152 toDiscard = false;
153 secure = false;
154
155 whenCreated = System.currentTimeMillis();
156 portlist = null;
157 this.header = header;
158 }
159
160 /**
161 * Constructs cookies from set-cookie or set-cookie2 header string.
162 * RFC 2965 section 3.2.2 set-cookie2 syntax indicates that one header line
163 * may contain more than one cookie definitions, so this is a static
164 * utility method instead of another constructor.
165 *
166 * @param header
|
126 * @param name
127 * a {@code String} specifying the name of the cookie
128 *
129 * @param value
130 * a {@code String} specifying the value of the cookie
131 *
132 * @throws IllegalArgumentException
133 * if the cookie name contains illegal characters
134 * @throws NullPointerException
135 * if {@code name} is {@code null}
136 *
137 * @see #setValue
138 * @see #setVersion
139 */
140 public HttpCookie(String name, String value) {
141 this(name, value, null /*header*/);
142 }
143
144 private HttpCookie(String name, String value, String header) {
145 name = name.trim();
146 if (name.isEmpty() || !isToken(name) || name.charAt(0) == '$') {
147 throw new IllegalArgumentException("Illegal cookie name");
148 }
149
150 this.name = name;
151 this.value = value;
152 toDiscard = false;
153 secure = false;
154
155 whenCreated = System.currentTimeMillis();
156 portlist = null;
157 this.header = header;
158 }
159
160 /**
161 * Constructs cookies from set-cookie or set-cookie2 header string.
162 * RFC 2965 section 3.2.2 set-cookie2 syntax indicates that one header line
163 * may contain more than one cookie definitions, so this is a static
164 * utility method instead of another constructor.
165 *
166 * @param header
|