MessageSupport { public static Set<String> parseTokens(final CharSequence src, final ParserCursor cursor) { Args.notNull(src, "Source"); Args.notNull(cursor, "Cursor"); final Set<String> tokens = new LinkedHashSet<>(); while (!cursor.atEnd()) { final int pos = cursor.getPos(); if (src.charAt(pos) == ',') { cursor.updatePos(pos + 1); } final String token = Tokenizer.INSTANCE.parseToken(src, cursor, COMMA); if (!TextUtils.isBlank(token)) { tokens.add(token); } } return tokens; } private  MessageSupport(); static void formatTokens(final CharArrayBuffer dst, final String... tokens); static void formatTokens(final CharArrayBuffer dst, final Set<String> tokens); static Header format(final String name, final Set<String> tokens); static Header format(final String name, final String... tokens); static Set<String> parseTokens(final CharSequence src, final ParserCursor cursor); static Set<String> parseTokens(final Header header); static void addContentTypeHeader(final HttpMessage message, final EntityDetails entity); static void addContentEncodingHeader(final HttpMessage message, final EntityDetails entity); static void addTrailerHeader(final HttpMessage message, final EntityDetails entity); static Iterator<HeaderElement> iterate(final MessageHeaders headers, final String name); static HeaderElement[] parse(final Header header); static boolean canResponseHaveBody(final String method, final HttpResponse response);  }
@Test public void testParseTokens() throws Exception { final String s = "a, b, c, c"; final ParserCursor cursor = new ParserCursor(0, s.length()); Assert.assertEquals(makeSet("a", "b", "c"), MessageSupport.parseTokens(s, cursor)); }
@Test public void testParseTokenHeader() throws Exception { final Header header = new BasicHeader(HttpHeaders.TRAILER, "a, b, c, c"); Assert.assertEquals(makeSet("a", "b", "c"), MessageSupport.parseTokens(header)); }
@Test public void testParseTokenBufferedHeader() throws Exception { final CharArrayBuffer buf = new CharArrayBuffer(128); buf.append("stuff: a, b, c, c"); final Header header = BufferedHeader.create(buf); Assert.assertEquals(makeSet("a", "b", "c"), MessageSupport.parseTokens(header)); }