BasicHeaderValueFormatter implements HeaderValueFormatter { @Override public void formatHeaderElement( final CharArrayBuffer buffer, final HeaderElement elem, final boolean quote) { Args.notNull(buffer, "Char array buffer"); Args.notNull(elem, "Header element"); buffer.append(elem.getName()); final String value = elem.getValue(); if (value != null) { buffer.append('='); formatValue(buffer, value, quote); } final int c = elem.getParameterCount(); if (c > 0) { for (int i = 0; i < c; i++) { buffer.append("; "); formatNameValuePair(buffer, elem.getParameter(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 testHEFormatting() 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 NameValuePair[] params = new NameValuePair[] {param1, param2, param3, param4}; final HeaderElement element = new BasicHeaderElement("name", "value", params); final CharArrayBuffer buf = new CharArrayBuffer(64); this.formatter.formatHeaderElement(buf, element, false); Assert.assertEquals("name=value; param=regular_stuff; param=\"this\\\\that\"; param=\"this,that\"; param", buf.toString()); }