/** * Get a lazy stream of chunks if the message body is chunked, or empty otherwise. * <p> * The last chunk is always the empty chunk, so once the empty chunk is received, * trying to consume another chunk will result in an error. * * @return lazy stream of chunks if the message body is chunked, or empty otherwise. * @throws IOException if an error occurs while consuming the body */ public Optional<Iterator<ChunkedBodyContents.Chunk>> asChunkStream() throws IOException { BodyConsumer consumer = framedBody.getBodyConsumer(); if (consumer instanceof BodyConsumer.ChunkedBodyConsumer) { try { return Optional.of(((BodyConsumer.ChunkedBodyConsumer) consumer) .consumeLazily(asRawStream())); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } throw e; } } else { return Optional.empty(); } }
/** * Get a lazy stream of chunks if the message body is chunked, or empty otherwise. * <p> * The last chunk is always the empty chunk, so once the empty chunk is received, * trying to consume another chunk will result in an error. * * @return lazy stream of chunks if the message body is chunked, or empty otherwise. * @throws IOException if an error occurs while consuming the body */ public Optional<Iterator<ChunkedBodyContents.Chunk>> asChunkStream() throws IOException { BodyConsumer consumer = framedBody.getBodyConsumer(); if (consumer instanceof BodyConsumer.ChunkedBodyConsumer) { try { return Optional.of(((BodyConsumer.ChunkedBodyConsumer) consumer) .consumeLazily(asRawStream())); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } throw e; } } else { return Optional.empty(); } }
@Override public BodyConsumer getBodyConsumer() { return new BodyConsumer.ChunkedBodyConsumer(bodyParser); }
@Override public BodyConsumer getBodyConsumer() { return new BodyConsumer.ChunkedBodyConsumer(bodyParser); }