@Override public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { entityStream.put(bodyPart.getBodyByteBuffer()); return STATE.CONTINUE; }
@Override public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { entityStream.put(bodyPart.getBodyByteBuffer()); return STATE.CONTINUE; }
@Override public void onContent(final Response jettyResponse, final ByteBuffer content) { try { // content must be consumed before returning from this method. if (content.hasArray()) { byte[] array = content.array(); byte[] buff = new byte[content.remaining()]; System.arraycopy(array, content.arrayOffset(), buff, 0, content.remaining()); entityStream.put(ByteBuffer.wrap(buff)); } else { byte[] buff = new byte[content.remaining()]; content.get(buff); entityStream.put(ByteBuffer.wrap(buff)); } } catch (final InterruptedException ex) { final ProcessingException pe = new ProcessingException(ex); entityStream.closeQueue(pe); // try to complete the future with an exception responseFuture.completeExceptionally(pe); Thread.currentThread().interrupt(); } }
synchronized void notifyDataAvailable(ByteBuffer availableData) { assertClosedForInput(); if (!availableData.hasRemaining()) { return; } if (mode == Mode.SYNCHRONOUS) { try { synchronousStream.put(availableData); } catch (InterruptedException e) { synchronousStream.closeQueue(e); } return; } data.add(availableData); if (readListener != null && callReadListener) { callDataAvailable(); } }
private synchronized void commitToMode() { // return if the mode has already been committed if (mode != Mode.UNDECIDED) { return; } // go asynchronous, if the user has made any move suggesting asynchronous mode if (readListener != null || listenerExecutor != null) { mode = Mode.ASYNCHRONOUS; return; } // go synchronous, if the user has not made any move suggesting asynchronous mode mode = Mode.SYNCHRONOUS; synchronousStream = new ByteBufferInputStream(); // move all buffered data to synchronous stream for (ByteBuffer b : data) { if (b == EOF) { synchronousStream.closeQueue(); } else if (b == ERROR) { synchronousStream.closeQueue(t); } else { try { synchronousStream.put(b); } catch (InterruptedException e) { synchronousStream.closeQueue(e); } } } }
@Override public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { entityStream.put(bodyPart.getBodyByteBuffer()); return STATE.CONTINUE; }
@Override public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { entityStream.put(bodyPart.getBodyByteBuffer()); return STATE.CONTINUE; }
@Override public void onContent(final Response jettyResponse, final ByteBuffer content) { try { // content must be consumed before returning from this method. if (content.hasArray()) { byte[] array = content.array(); byte[] buff = new byte[content.remaining()]; System.arraycopy(array, content.arrayOffset(), buff, 0, content.remaining()); entityStream.put(ByteBuffer.wrap(buff)); } else { byte[] buff = new byte[content.remaining()]; content.get(buff); entityStream.put(ByteBuffer.wrap(buff)); } } catch (final InterruptedException ex) { final ProcessingException pe = new ProcessingException(ex); entityStream.closeQueue(pe); // try to complete the future with an exception responseFuture.completeExceptionally(pe); Thread.currentThread().interrupt(); } }