/** * Sends content as provided by the given {@link InputSupplier} as small chunks to the given * {@link BodyConsumer}. */ private void sendChunks( InputSupplier<? extends InputStream> inputSupplier, int chunkSize, BodyConsumer bodyConsumer, HttpResponder responder) throws IOException { InputStream input = inputSupplier.getInput(); try { byte[] bytes = new byte[chunkSize]; int len = input.read(bytes); while (len >= 0) { bodyConsumer.chunk(ChannelBuffers.copiedBuffer(bytes, 0, len), responder); len = input.read(bytes); } bodyConsumer.finished(responder); } catch (Exception e) { bodyConsumer.handleError(e); } finally { input.close(); } }