* Reads the next cookie available or null.
*
* @return The next cookie available or null.
*/
public Cookie readCookie() throws IOException {
Cookie result = null;
Parameter pair = readPair();
if (this.globalVersion == -1) {
// Cookies version not yet detected
if (pair.getName().equalsIgnoreCase(NAME_VERSION)) {
if (pair.getValue() != null) {
this.globalVersion = Integer.parseInt(pair.getValue());
} else {
throw new IOException(
"Empty cookies version attribute detected. Please check your cookie header");
}
} else {
// Set the default version for old Netscape cookies
this.globalVersion = 0;
}
}
while ((pair != null) && (pair.getName().charAt(0) == '$')) {
// Unexpected special attribute
// Silently ignore it as it may have been introduced by new
// specifications
pair = readPair();
}
if (pair != null) {
// Set the cookie name and value
result = new Cookie(this.globalVersion, pair.getName(), pair
.getValue());
pair = readPair();
}
while ((pair != null) && (pair.getName().charAt(0) == '$')) {
if (pair.getName().equalsIgnoreCase(NAME_PATH)) {
result.setPath(pair.getValue());
} else if (pair.getName().equalsIgnoreCase(NAME_DOMAIN)) {
result.setDomain(pair.getValue());
} else {
// Unexpected special attribute
// Silently ignore it as it may have been introduced by new
// specifications
}