public ByteBufferEntity(final ByteBuffer buffer, final ContentType contentType) { super(); Args.notNull(buffer, "Source byte buffer"); this.buffer = buffer; if (contentType != null) { setContentType(contentType.toString()); } }
@Test public void testBasics() throws Exception { final ByteBuffer bytes = ByteBuffer.wrap("Message content".getBytes(StandardCharsets.US_ASCII)); final ByteBufferEntity httpentity = new ByteBufferEntity(bytes); Assert.assertEquals(bytes.capacity(), httpentity.getContentLength()); Assert.assertNotNull(httpentity.getContent()); Assert.assertTrue(httpentity.isRepeatable()); Assert.assertFalse(httpentity.isStreaming()); }
@Test public void testWriteTo() throws Exception { final ByteBuffer bytes = ByteBuffer.wrap("Message content".getBytes(StandardCharsets.US_ASCII)); final ByteBufferEntity httpentity = new ByteBufferEntity(bytes); httpentity.writeTo(out); byte[] bytes2 = out.toByteArray(); Assert.assertNotNull(bytes2); httpentity.writeTo(out); bytes2 = out.toByteArray(); Assert.assertNotNull(bytes2); httpentity.writeTo(null); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException ex) {
@Test(expected=IllegalArgumentException.class) public void testIllegalConstructorNullByteArray() throws Exception { new ByteBufferEntity(null); }
public ByteBufferEntity(final ByteBuffer buffer, final ContentType contentType) { super(); Args.notNull(buffer, "Source byte buffer"); this.buffer = buffer; if (contentType != null) { setContentType(contentType.toString()); } }