EntityUtils { public static List<NameValuePair> parse(final HttpEntity entity) throws IOException { return parse(entity, DEFAULT_ENTITY_RETURN_MAX_LENGTH); } private  EntityUtils(); static void consumeQuietly(final HttpEntity entity); static void consume(final HttpEntity entity); static byte[] toByteArray(final HttpEntity entity); static byte[] toByteArray(final HttpEntity entity, final int maxResultLength); static String toString(
            final HttpEntity entity, final Charset defaultCharset); static String toString(
            final HttpEntity entity, final Charset defaultCharset, final int maxResultLength); static String toString(
            final HttpEntity entity, final String defaultCharset); static String toString(
            final HttpEntity entity, final String defaultCharset, final int maxResultLength); static String toString(final HttpEntity entity); static String toString(final HttpEntity entity, final int maxResultLength); static List<NameValuePair> parse(final HttpEntity entity); static List<NameValuePair> parse(final HttpEntity entity, final int maxStreamLength);  }
@Test public void testParseEntity() throws Exception { final StringEntity entity1 = new StringEntity("Name1=Value1", ContentType.APPLICATION_FORM_URLENCODED); final List<NameValuePair> result = EntityUtils.parse(entity1); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name1", "Value1"); final StringEntity entity2 = new StringEntity("Name1=Value1", ContentType.parse("text/test")); Assert.assertTrue(EntityUtils.parse(entity2).isEmpty()); }
@Test public void testParseUTF8Entity() throws Exception { final String ru_hello = constructString(RUSSIAN_HELLO); final String ch_hello = constructString(SWISS_GERMAN_HELLO); final List <NameValuePair> parameters = new ArrayList<>(); parameters.add(new BasicNameValuePair("russian", ru_hello)); parameters.add(new BasicNameValuePair("swiss", ch_hello)); final String s = WWWFormCodec.format(parameters, StandardCharsets.UTF_8); Assert.assertEquals("russian=%D0%92%D1%81%D0%B5%D0%BC_%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" + "&swiss=Gr%C3%BCezi_z%C3%A4m%C3%A4", s); final StringEntity entity = new StringEntity(s, ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8)); final List<NameValuePair> result = EntityUtils.parse(entity); Assert.assertEquals(2, result.size()); assertNameValuePair(result.get(0), "russian", ru_hello); assertNameValuePair(result.get(1), "swiss", ch_hello); }