@Test public void testUnknownLengthContentToString() throws Exception { final byte[] bytes = "Message content".getBytes(StandardCharsets.ISO_8859_1); final BasicHttpEntity entity = new BasicHttpEntity(new ByteArrayInputStream(bytes), -1, null); final String s = EntityUtils.toString(entity, "ISO-8859-1"); Assert.assertEquals("Message content", s); }
private static String toString(final HttpEntity entity, final ContentType contentType, final int maxResultLength) throws IOException { Args.notNull(entity, "HttpEntity"); final int contentLength = toContentLength((int) Args.checkContentLength(entity)); try (final InputStream inStream = entity.getContent()) { if (inStream == null) { return null; } Charset charset = null; if (contentType != null) { charset = contentType.getCharset(); if (charset == null) { final ContentType defaultContentType = CONTENT_TYPE_MAP.get(contentType.getMimeType()); charset = defaultContentType != null ? defaultContentType.getCharset() : null; } } return toCharArrayBuffer(inStream, contentLength, charset, maxResultLength).toString(); } }
EntityUtils { private static String toString(final HttpEntity entity, final ContentType contentType, final int maxResultLength) throws IOException { Args.notNull(entity, "HttpEntity"); final int contentLength = toContentLength((int) Args.checkContentLength(entity)); try (final InputStream inStream = entity.getContent()) { if (inStream == null) { return null; } Charset charset = null; if (contentType != null) { charset = contentType.getCharset(); if (charset == null) { final ContentType defaultContentType = CONTENT_TYPE_MAP.get(contentType.getMimeType()); charset = defaultContentType != null ? defaultContentType.getCharset() : null; } } return toCharArrayBuffer(inStream, contentLength, charset, maxResultLength).toString(); } } }
EntityUtils { private static String toString(final HttpEntity entity, final ContentType contentType, final int maxResultLength) throws IOException { Args.notNull(entity, "HttpEntity"); final int contentLength = toContentLength((int) Args.checkContentLength(entity)); try (final InputStream inStream = entity.getContent()) { if (inStream == null) { return null; } Charset charset = null; if (contentType != null) { charset = contentType.getCharset(); if (charset == null) { final ContentType defaultContentType = CONTENT_TYPE_MAP.get(contentType.getMimeType()); charset = defaultContentType != null ? defaultContentType.getCharset() : null; } } return toCharArrayBuffer(inStream, contentLength, charset, maxResultLength).toString(); } } private  EntityUtils(); }
EntityUtils { private static String toString(final HttpEntity entity, final ContentType contentType, final int maxResultLength) throws IOException { Args.notNull(entity, "HttpEntity"); final int contentLength = toContentLength((int) Args.checkContentLength(entity)); try (final InputStream inStream = entity.getContent()) { if (inStream == null) { return null; } Charset charset = null; if (contentType != null) { charset = contentType.getCharset(); if (charset == null) { final ContentType defaultContentType = CONTENT_TYPE_MAP.get(contentType.getMimeType()); charset = defaultContentType != null ? defaultContentType.getCharset() : null; } } return toCharArrayBuffer(inStream, contentLength, charset, maxResultLength).toString(); } } 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); }
EntityUtils { private static String toString(final HttpEntity entity, final ContentType contentType, final int maxResultLength) throws IOException { Args.notNull(entity, "HttpEntity"); final int contentLength = toContentLength((int) Args.checkContentLength(entity)); try (final InputStream inStream = entity.getContent()) { if (inStream == null) { return null; } Charset charset = null; if (contentType != null) { charset = contentType.getCharset(); if (charset == null) { final ContentType defaultContentType = CONTENT_TYPE_MAP.get(contentType.getMimeType()); charset = defaultContentType != null ? defaultContentType.getCharset() : null; } } return toCharArrayBuffer(inStream, contentLength, charset, maxResultLength).toString(); } } 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);  }