/** * Generates textual representation of this content type which can be used as the value * of a {@code Content-Type} header. */ @Override public String toString() { final CharArrayBuffer buf = new CharArrayBuffer(64); buf.append(this.mimeType); if (this.params != null) { buf.append("; "); BasicHeaderValueFormatter.INSTANCE.formatParameters(buf, this.params, false); } else if (this.charset != null) { buf.append("; charset="); buf.append(this.charset.name()); } return buf.toString(); }
/** * Generates textual representation of this content type which can be used as the value * of a {@code Content-Type} header. */ @Override public String toString() { final CharArrayBuffer buf = new CharArrayBuffer(64); buf.append(this.mimeType); if (this.params != null) { buf.append("; "); BasicHeaderValueFormatter.INSTANCE.formatParameters(buf, this.params, false); } else if (this.charset != null) { buf.append("; charset="); buf.append(this.charset.name()); } return buf.toString(); }
@Test public void testParamsFormatting() 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[] params = new NameValuePair[] {param1, param2, param3}; final CharArrayBuffer buf = new CharArrayBuffer(64); buf.clear(); this.formatter.formatParameters(buf, params, false); Assert.assertEquals("param=regular_stuff; param=\"this\\\\that\"; param=\"this,that\"", buf.toString()); buf.clear(); this.formatter.formatParameters(buf, params, true); Assert.assertEquals("param=\"regular_stuff\"; param=\"this\\\\that\"; param=\"this,that\"", buf.toString()); }
this.formatter.formatParameters(null, params, false); Assert.fail("IllegalArgumentException should habe been thrown"); } catch (final IllegalArgumentException ex) { this.formatter.formatParameters(buf, null, false); Assert.fail("IllegalArgumentException should habe been thrown"); } catch (final IllegalArgumentException ex) {