StringEntity extends AbstractHttpEntity { @Override public final void writeTo(final OutputStream outStream) throws IOException { Args.notNull(outStream, "Output stream"); outStream.write(this.content); outStream.flush(); } StringEntity(
            final String string, final ContentType contentType, final String contentEncoding, final boolean chunked);  StringEntity(final String string, final ContentType contentType, final boolean chunked);  StringEntity(final String string, final ContentType contentType);  StringEntity(final String string, final Charset charset);  StringEntity(final String string, final Charset charset, final boolean chunked);  StringEntity(final String string); @Override final boolean isRepeatable(); @Override final long getContentLength(); @Override final InputStream getContent(); @Override final void writeTo(final OutputStream outStream); @Override final boolean isStreaming(); @Override final void close();  }
@Test public void testWriteTo() throws Exception { final String s = "Message content"; final byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1); final StringEntity httpentity = new StringEntity(s); ByteArrayOutputStream out = new ByteArrayOutputStream(); httpentity.writeTo(out); byte[] bytes2 = out.toByteArray(); Assert.assertNotNull(bytes2); Assert.assertEquals(bytes.length, bytes2.length); for (int i = 0; i < bytes.length; i++) { Assert.assertEquals(bytes[i], bytes2[i]); } out = new ByteArrayOutputStream(); httpentity.writeTo(out); bytes2 = out.toByteArray(); Assert.assertNotNull(bytes2); Assert.assertEquals(bytes.length, bytes2.length); for (int i = 0; i < bytes.length; i++) { Assert.assertEquals(bytes[i], bytes2[i]); } try { httpentity.writeTo(null); Assert.fail("NullPointerException should have been thrown"); } catch (final NullPointerException ex) { } }