BasicHeaderValueFormatter implements HeaderValueFormatter { @Override public void formatElements( final CharArrayBuffer buffer, final HeaderElement[] elems, final boolean quote) { Args.notNull(buffer, "Char array buffer"); Args.notNull(elems, "Header element array"); for (int i = 0; i < elems.length; i++) { if (i > 0) { buffer.append(", "); } formatHeaderElement(buffer, elems[i], quote); } } BasicHeaderValueFormatter(); @Override void formatElements(
            final CharArrayBuffer buffer, final HeaderElement[] elems, final boolean quote); @Override void formatHeaderElement(
            final CharArrayBuffer buffer, final HeaderElement elem, final boolean quote); @Override void formatParameters(
            final CharArrayBuffer buffer, final NameValuePair[] nvps, final boolean quote); @Override void formatNameValuePair(
            final CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote); final static BasicHeaderValueFormatter INSTANCE; }
@Test public void testElementsFormatting() throws Exception { final NameValuePair param1 = new BasicNameValuePair("param", "regular_stuff"); final NameValuePair param2 = new BasicNameValuePair("param", "this\\that"); final NameValuePair param3 = new BasicNameValuePair("param", "this,that"); final NameValuePair param4 = new BasicNameValuePair("param", null); final HeaderElement element1 = new BasicHeaderElement("name1", "value1", new NameValuePair[] {param1}); final HeaderElement element2 = new BasicHeaderElement("name2", "value2", new NameValuePair[] {param2}); final HeaderElement element3 = new BasicHeaderElement("name3", "value3", new NameValuePair[] {param3}); final HeaderElement element4 = new BasicHeaderElement("name4", "value4", new NameValuePair[] {param4}); final HeaderElement element5 = new BasicHeaderElement("name5", null); final HeaderElement[] elements = new HeaderElement[] {element1, element2, element3, element4, element5}; final CharArrayBuffer buf = new CharArrayBuffer(64); this.formatter.formatElements(buf, elements, false); Assert.assertEquals("name1=value1; param=regular_stuff, name2=value2; " + "param=\"this\\\\that\", name3=value3; param=\"this,that\", " + "name4=value4; param, name5", buf.toString()); }