@Override public ByteBuffer getResponseBodyAsByteBuffer() { int length = 0; for (HttpResponseBodyPart part : bodyParts) length += part.length(); ByteBuffer target = ByteBuffer.wrap(new byte[length]); for (HttpResponseBodyPart part : bodyParts) target.put(part.getBodyPartBytes()); target.flip(); return target; }
@Override public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { // body arrived, flush headers if (!responseSet) { response = responseBuilder.build(); responseSet = true; headersArrived.countDown(); } output.write(bodyPart.getBodyPartBytes()); return State.CONTINUE; }
public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { stream.write(bodyPart.getBodyPartBytes()); if (bodyPart.getBodyPartBytes().length == 0) { return State.ABORT; } return State.CONTINUE; }
public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { stream.write(bodyPart.getBodyPartBytes()); return State.CONTINUE; }
private static byte[] getBytes(List<HttpResponseBodyPart> bodyParts) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); for (HttpResponseBodyPart part : bodyParts) { bytes.write(part.getBodyPartBytes()); } return bytes.toByteArray(); }
@Override public State onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { State s = State.CONTINUE; if (accumulateResponseBytes) { s = super.onBodyPartReceived(content); } fireOnBytesReceived(content.getBodyPartBytes()); return s; }
public State onBodyPartReceived(HttpResponseBodyPart e) throws Exception { byte[] bytes = e.getBodyPartBytes(); if (bytes.length != 0) { String s = new String(bytes); logger.info("got part: {}", s); logger.warn("Sampling stacktrace.", new Throwable("trace that, we should not get called for empty body.")); queue.put(s); } return State.CONTINUE; }
public State onBodyPartReceived(HttpResponseBodyPart event) { String s = new String(event.getBodyPartBytes()); result.compareAndSet(-1, new Integer(s.trim().equals("") ? "-1" : s)); return State.CONTINUE; }
public State onBodyPartReceived(HttpResponseBodyPart e) throws Exception { if (e.length() != 0) { String s = new String(e.getBodyPartBytes()); logger.info("got part: {}", s); queue.put(s); } return State.CONTINUE; }
public byte[] getBytes() throws Throwable { List<HttpResponseBodyPart> bodyParts = subscriber.getElements(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); for (HttpResponseBodyPart part : bodyParts) { bytes.write(part.getBodyPartBytes()); } return bytes.toByteArray(); } }
@Test public void testOnBodyPartReceived() throws Exception { ResumableAsyncHandler handler = new ResumableAsyncHandler(); HttpResponseBodyPart bodyPart = mock(HttpResponseBodyPart.class); when(bodyPart.getBodyPartBytes()).thenReturn(new byte[0]); ByteBuffer buffer = ByteBuffer.allocate(0); when(bodyPart.getBodyByteBuffer()).thenReturn(buffer); State state = handler.onBodyPartReceived(bodyPart); assertEquals(state, AsyncHandler.State.CONTINUE, "State should be CONTINUE for a successful onBodyPartReceived"); }
@Override public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { if (accumulateBody) { responseBuilder.accumulate(bodyPart); } State state = State.CONTINUE; try { resumableListener.onBytesReceived(bodyPart.getBodyByteBuffer()); } catch (IOException ex) { return AsyncHandler.State.ABORT; } if (decoratedAsyncHandler != null) { state = decoratedAsyncHandler.onBodyPartReceived(bodyPart); } byteTransferred.addAndGet(bodyPart.getBodyPartBytes().length); resumableProcessor.put(url, byteTransferred.get()); return state; }
@Test public void testOnBodyPartReceivedWithDecoratedAsyncHandler() throws Exception { HttpResponseBodyPart bodyPart = mock(HttpResponseBodyPart.class); when(bodyPart.getBodyPartBytes()).thenReturn(new byte[0]); ByteBuffer buffer = ByteBuffer.allocate(0); when(bodyPart.getBodyByteBuffer()).thenReturn(buffer); @SuppressWarnings("unchecked") AsyncHandler<Response> decoratedAsyncHandler = mock(AsyncHandler.class); when(decoratedAsyncHandler.onBodyPartReceived(bodyPart)).thenReturn(State.CONTINUE); // following is needed to set the url variable HttpResponseStatus mockResponseStatus = mock(HttpResponseStatus.class); when(mockResponseStatus.getStatusCode()).thenReturn(200); Uri uri = Uri.create("http://non.null"); when(mockResponseStatus.getUri()).thenReturn(uri); ResumableAsyncHandler handler = new ResumableAsyncHandler(decoratedAsyncHandler); handler.onStatusReceived(mockResponseStatus); State state = handler.onBodyPartReceived(bodyPart); assertEquals(state, State.CONTINUE, "State should be equal to the state returned from decoratedAsyncHandler"); }
public void onPing(HttpResponseBodyPart part) { for (WebSocketListener listener : listeners) { if (listener instanceof WebSocketPingListener) // bytes are cached in the part WebSocketPingListener.class.cast(listener).onPing(part.getBodyPartBytes()); } }
public void onPong(HttpResponseBodyPart part) { for (WebSocketListener listener : listeners) { if (listener instanceof WebSocketPongListener) // bytes are cached in the part WebSocketPongListener.class.cast(listener).onPong(part.getBodyPartBytes()); } } }
public void onPing(HttpResponseBodyPart part) { for (WebSocketListener listener : listeners) { if (listener instanceof WebSocketPingListener) // bytes are cached in the part WebSocketPingListener.class.cast(listener).onPing(part.getBodyPartBytes()); } }
@Override public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { int length = 0; for (HttpResponseBodyPart part : bodyParts) length += part.length(); ByteBuffer target = ByteBuffer.wrap(new byte[length]); for (HttpResponseBodyPart part : bodyParts) target.put(part.getBodyPartBytes()); return target; }
@Override public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { int length = 0; for (HttpResponseBodyPart part : bodyParts) length += part.length(); ByteBuffer target = ByteBuffer.wrap(new byte[length]); for (HttpResponseBodyPart part : bodyParts) target.put(part.getBodyPartBytes()); return target; }
public void onPong(HttpResponseBodyPart part) { for (WebSocketListener listener : listeners) { if (listener instanceof WebSocketPongListener) // bytes are cached in the part WebSocketPongListener.class.cast(listener).onPong(part.getBodyPartBytes()); } } }
@Override public State onBodyPartReceived(final HttpResponseBodyPart bodyPart) throws Exception { if (nonNull(bodyPart) && nonNull(bodyPart.getBodyByteBuffer())) { bytesSent += bodyPart.getBodyPartBytes().length; isLast = bodyPart.isLast(); context.getResponse().getOutputStream().write(bodyPart.getBodyPartBytes()); } return State.CONTINUE; }