NetscapeDraftHeaderParser { public HeaderElement parseHeader( final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } NameValuePair nvp = parseNameValuePair(buffer, cursor); List<NameValuePair> params = new ArrayList<NameValuePair>(); while (!cursor.atEnd()) { NameValuePair param = parseNameValuePair(buffer, cursor); params.add(param); } return new BasicHeaderElement( nvp.getName(), nvp.getValue(), params.toArray(new NameValuePair[params.size()])); } NetscapeDraftHeaderParser(); HeaderElement parseHeader(
            final CharArrayBuffer buffer,
            final ParserCursor cursor); final static NetscapeDraftHeaderParser DEFAULT; }
@Test public void testNetscapeCookieParsing() throws Exception { NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT; String s = "name = value; test; test1 = stuff,with,commas ;" + " test2 = \"stuff, stuff\"; test3=\"stuff"; CharArrayBuffer buffer = new CharArrayBuffer(16); buffer.append(s); ParserCursor cursor = new ParserCursor(0, s.length()); HeaderElement he = parser.parseHeader(buffer, cursor); Assert.assertEquals("name", he.getName()); Assert.assertEquals("value", he.getValue()); NameValuePair[] params = he.getParameters(); Assert.assertEquals("test", params[0].getName()); Assert.assertEquals(null, params[0].getValue()); Assert.assertEquals("test1", params[1].getName()); Assert.assertEquals("stuff,with,commas", params[1].getValue()); Assert.assertEquals("test2", params[2].getName()); Assert.assertEquals("\"stuff, stuff\"", params[2].getValue()); Assert.assertEquals("test3", params[3].getName()); Assert.assertEquals("\"stuff", params[3].getValue()); Assert.assertEquals(s.length(), cursor.getPos()); Assert.assertTrue(cursor.atEnd()); s = " "; buffer = new CharArrayBuffer(16); buffer.append(s); cursor = new ParserCursor(0, s.length()); he = parser.parseHeader(buffer, cursor); Assert.assertEquals("", he.getName()); Assert.assertEquals(null, he.getValue()); }