Code example for BasicHttpEntity

Methods: setContent, setContentLength

0
        assertNull(bytes);
    } 
 
    public void testMaxIntContentToByteArray() throws Exception { 
        byte[] content = "Message content".getBytes("ISO-8859-1");
        BasicHttpEntity httpentity = new BasicHttpEntity();
        httpentity.setContent(new ByteArrayInputStream(content));
        httpentity.setContentLength(Integer.MAX_VALUE + 100L);
        try { 
            EntityUtils.toByteArray(httpentity);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
    } 
 
    public void testUnknownLengthContentToByteArray() throws Exception { 
        byte[] bytes = "Message content".getBytes("ISO-8859-1");
        BasicHttpEntity httpentity = new BasicHttpEntity();
        httpentity.setContent(new ByteArrayInputStream(bytes));
        httpentity.setContentLength(-1L);