UrlEncodedFormEntityWriter implements EntityWriter { public void writeTo(Request request, OutputStream out) throws IOException { Charset charset = request.getMethodConfig().getCharset(); Writer writer = new OutputStreamWriter(out, charset); join(writer, request.getEncodedParamsIterator(FORM), '&'); writer.flush(); }  String getContentType(Request request); int getContentLength(Request request); void writeTo(Request request, OutputStream out);  }
@Test public void writeToShouldUseRequestFormParamsWithGivenCharset() throws IOException { Iterator<EncodedPair> pairs = asList( Pairs.toPair("p1", "v%201", Values.UTF8, true), Pairs.toPair("p2", "v£ 1", Values.UTF8, false) ).iterator(); Request mockRequest = mockRequest(); when(mockRequest.getEncodedParamsIterator(ParamType.FORM)).thenReturn(pairs); ByteArrayOutputStream out = new ByteArrayOutputStream(); toTest.writeTo(mockRequest, out); assertEquals("p1=v%201&p2=v%C2%A3%201", out.toString("utf-8")); }