use of org.apache.hc.core5.http.io.entity.AbstractHttpEntity in project httpcomponents-core by apache.
the class TestEntityUtils method testContentWithInvalidContentTypeToString.
@Test
public void testContentWithInvalidContentTypeToString() throws Exception {
final String content = constructString(RUSSIAN_HELLO);
final byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
final HttpEntity entity = new AbstractHttpEntity("text/plain; charset=nosuchcharset", null) {
@Override
public InputStream getContent() throws IOException, UnsupportedOperationException {
return new ByteArrayInputStream(bytes);
}
@Override
public boolean isStreaming() {
return false;
}
@Override
public long getContentLength() {
return bytes.length;
}
@Override
public void close() throws IOException {
}
};
final String s = EntityUtils.toString(entity, "UTF-8");
Assertions.assertEquals(content, s);
}
Aggregations