CachingAsyncDataConsumer( final AsyncExecCallback fallback, final HttpResponse backendResponse, final EntityDetails entityDetails) { this.fallback = fallback; this.backendResponse = backendResponse; this.entityDetails = entityDetails; this.writtenThrough = new AtomicBoolean(false); this.bufferRef = new AtomicReference<>(entityDetails != null ? new ByteArrayBuffer(1024) : null); this.dataConsumerRef = new AtomicReference<>(); }
@Override public byte[] get() throws ResourceIOException { final File file = this.fileRef.get(); if (file == null) { throw new ResourceIOException("Resouce already dispoased"); } try (final InputStream in = new FileInputStream(file)) { final ByteArrayBuffer buf = new ByteArrayBuffer(1024); final byte[] tmp = new byte[2048]; int len; while ((len = in.read(tmp)) != -1) { buf.append(tmp, 0, len); } return buf.toByteArray(); } catch (final IOException ex) { throw new ResourceIOException(ex.getMessage(), ex); } }
public static ByteArrayBuffer getRandomBuffer(final int nbytes) { final ByteArrayBuffer buf = new ByteArrayBuffer(nbytes); buf.setLength(nbytes); new Random().nextBytes(buf.array()); return buf; }
final HttpEntity entity = backendResponse.getEntity(); if (entity != null) { buf = new ByteArrayBuffer(1024); final InputStream inStream = entity.getContent(); final byte[] tmp = new byte[2048];
private Continuation(final int streamId, final int type, final boolean endStream) { this.streamId = streamId; this.type = type; this.endStream = endStream; this.headerBuffer = new ByteArrayBuffer(1024); }
public BasicAsyncEntityConsumer() { super(); this.buffer = new ByteArrayBuffer(1024); }
public BasicAsyncEntityConsumer() { super(); this.buffer = new ByteArrayBuffer(1024); }
@Test public void testCombinedEntityBasics() throws Exception { final HttpEntity httpEntity = mock(HttpEntity.class); when(httpEntity.getContent()).thenReturn( new ByteArrayInputStream(new byte[] { 6, 7, 8, 9, 10 })); final ByteArrayBuffer buf = new ByteArrayBuffer(1024); final byte[] tmp = new byte[] { 1, 2, 3, 4, 5 }; buf.append(tmp, 0, tmp.length); final CombinedEntity entity = new CombinedEntity(httpEntity, buf); Assert.assertEquals(-1, entity.getContentLength()); Assert.assertFalse(entity.isRepeatable()); Assert.assertTrue(entity.isStreaming()); Assert.assertArrayEquals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, EntityUtils.toByteArray(entity)); verify(httpEntity).getContent(); entity.close(); verify(httpEntity).close(); }
CachingAsyncDataConsumer( final AsyncExecCallback fallback, final HttpResponse backendResponse, final EntityDetails entityDetails) { this.fallback = fallback; this.backendResponse = backendResponse; this.entityDetails = entityDetails; this.writtenThrough = new AtomicBoolean(false); this.bufferRef = new AtomicReference<>(entityDetails != null ? new ByteArrayBuffer(1024) : null); this.dataConsumerRef = new AtomicReference<>(); }
static ByteArrayBuffer encode( final Charset charset, final String string) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab; }
HPackEncoder(final OutboundDynamicTable dynamicTable, final CharsetEncoder charsetEncoder) { this.dynamicTable = dynamicTable != null ? dynamicTable : new OutboundDynamicTable(); this.huffmanBuf = new ByteArrayBuffer(128); this.charsetEncoder = charsetEncoder; }
HPackDecoder(final InboundDynamicTable dynamicTable, final CharsetDecoder charsetDecoder) { this.dynamicTable = dynamicTable != null ? dynamicTable : new InboundDynamicTable(); this.contentBuf = new ByteArrayBuffer(256); this.charsetDecoder = charsetDecoder; }
public ByteArrayAsyncEntityConsumer() { super(); this.buffer = new ByteArrayBuffer(1024); }
@Test public void testAppendCharArrayAsAscii() throws Exception { final String s1 = "stuff"; final String s2 = " and more stuff"; final char[] b1 = s1.toCharArray(); final char[] b2 = s2.toCharArray(); final ByteArrayBuffer buffer = new ByteArrayBuffer(8); buffer.append(b1, 0, b1.length); buffer.append(b2, 0, b2.length); Assert.assertEquals(s1 + s2, new String(buffer.toByteArray(), "US-ASCII")); }
@Test public void testAppendNullCharArray() throws Exception { final ByteArrayBuffer buffer = new ByteArrayBuffer(8); buffer.append((char[])null, 0, 0); Assert.assertEquals(0, buffer.length()); }
@Test public void testAppendEmptyCharArray() throws Exception { final ByteArrayBuffer buffer = new ByteArrayBuffer(8); buffer.append(new char[] {}, 0, 0); Assert.assertEquals(0, buffer.length()); }
@Test public void testSetLength() throws Exception { final ByteArrayBuffer buffer = new ByteArrayBuffer(4); buffer.setLength(2); Assert.assertEquals(2, buffer.length()); }
@Test public void testAppendNullCharArrayBuffer() throws Exception { final ByteArrayBuffer buffer = new ByteArrayBuffer(8); buffer.append((CharArrayBuffer)null, 0, 0); Assert.assertEquals(0, buffer.length()); }
@Test public void testEnsureCapacity() throws Exception { final ByteArrayBuffer buffer = new ByteArrayBuffer(4); buffer.ensureCapacity(2); Assert.assertEquals(4, buffer.capacity()); buffer.ensureCapacity(8); Assert.assertEquals(8, buffer.capacity()); }
@Test public void testAppendOneByte() throws Exception { final ByteArrayBuffer buffer = new ByteArrayBuffer(4); Assert.assertEquals(4, buffer.capacity()); final byte[] tmp = new byte[] { 1, 127, -1, -128, 1, -2}; for (final byte element : tmp) { buffer.append(element); } Assert.assertEquals(8, buffer.capacity()); Assert.assertEquals(6, buffer.length()); for (int i = 0; i < tmp.length; i++) { Assert.assertEquals(tmp[i], buffer.byteAt(i)); } }