@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader(new FramedBody.Chunked(getBodyDecoder(), metadataParser), new InputStreamChunkEncoder(stream, chunkLength)); }
/** * @return the raw HTTP message's body as bytes. * <p> * This method does not unframe nor decode the body in case the body is encoded. * To get the decoded body, use * {@link #decodeBody()} or {@link #decodeBodyToString(Charset)}. * @throws IOException if an error occurs while consuming the message body */ public byte[] asRawBytes() throws IOException { return framedBody.getBodyConsumer().consume(asRawStream()); }
@Override public void writeTo(OutputStream out, int bufferSize) throws IOException { markConsumed(); super.writeTo(out, bufferSize); }
@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader( new FramedBody.ContentLength(getBodyDecoder(), (long) bytes.length), new ByteArrayInputStream(bytes)); }
/** * Read the raw HTTP message body, simultaneously writing it to the given output. * <p> * This method may not validate the full HTTP message before it starts writing it out. * To perform a full validation first, call {@link #eager()} to get an eager reader. * * @param out to write the HTTP body to * @param bufferSize size of the buffer to use for writing, if possible * @throws IOException if an error occurs while writing the message * @see BodyReader#writeDecodedTo(OutputStream, int) */ public void writeTo(OutputStream out, int bufferSize) throws IOException { framedBody.getBodyConsumer().consumeInto(asRawStream(), out, bufferSize); }
/** * @return the body of the HTTP message as a {@link ChunkedBodyContents} if the body indeed used * the chunked transfer coding. If the body was not chunked, this method returns an empty value. * @throws IOException if an error occurs while consuming the message body */ public Optional<ChunkedBodyContents> asChunkedBodyContents() throws IOException { return framedBody.use( cl -> Optional.empty(), chunked -> Optional.of(chunked.getContents(asRawStream())), ct -> Optional.empty()); }
@Override public OptionalLong getLengthIfKnown() { try { return getFramedBody().use( cl -> OptionalLong.of(cl.getBodyLength()), chunked -> OptionalLong.empty(), ct -> OptionalLong.empty()); } catch (IOException e) { return OptionalLong.empty(); } }
@Override public byte[] asRawBytes() throws IOException { markConsumed(); return super.asRawBytes(); }
@Override public Optional<ChunkedBodyContents> asChunkedBodyContents() throws IOException { markConsumed(); return super.asChunkedBodyContents(); }
@Override public void consumeDataInto(InputStream inputStream, OutputStream outputStream, int bufferSize) throws IOException { consumeInto(inputStream, outputStream, bufferSize); } }
@Override public String toString() { return asString(UTF_8); } }
@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader(new FramedBody.Chunked(getBodyDecoder(), metadataParser), new InputStreamChunkEncoder(stream, chunkLength)); }
/** * @return the raw HTTP message's body as bytes. * <p> * This method does not unframe nor decode the body in case the body is encoded. * To get the decoded body, use * {@link #decodeBody()} or {@link #decodeBodyToString(Charset)}. * @throws IOException if an error occurs while consuming the message body */ public byte[] asRawBytes() throws IOException { return framedBody.getBodyConsumer().consume(asRawStream()); }
@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader( new FramedBody.ContentLength(getBodyDecoder(), (long) bytes.length), new ByteArrayInputStream(bytes)); }
/** * Read the raw HTTP message body, simultaneously writing it to the given output. * <p> * This method may not validate the full HTTP message before it starts writing it out. * To perform a full validation first, call {@link #eager()} to get an eager reader. * * @param out to write the HTTP body to * @param bufferSize size of the buffer to use for writing, if possible * @throws IOException if an error occurs while writing the message * @see BodyReader#writeDecodedTo(OutputStream, int) */ public void writeTo(OutputStream out, int bufferSize) throws IOException { framedBody.getBodyConsumer().consumeInto(asRawStream(), out, bufferSize); }
/** * @return the body of the HTTP message as a {@link ChunkedBodyContents} if the body indeed used * the chunked transfer coding. If the body was not chunked, this method returns an empty value. * @throws IOException if an error occurs while consuming the message body */ public Optional<ChunkedBodyContents> asChunkedBodyContents() throws IOException { return framedBody.use( cl -> Optional.empty(), chunked -> Optional.of(chunked.getContents(asRawStream())), ct -> Optional.empty()); }
@Override public OptionalLong getLengthIfKnown() { try { return getFramedBody().use( cl -> OptionalLong.of(cl.getBodyLength()), chunked -> OptionalLong.empty(), ct -> OptionalLong.empty()); } catch (IOException e) { return OptionalLong.empty(); } }
@Override public void writeTo(OutputStream out, int bufferSize) throws IOException { markConsumed(); super.writeTo(out, bufferSize); }
@Override public byte[] asRawBytes() throws IOException { markConsumed(); return super.asRawBytes(); }
@Override public Optional<ChunkedBodyContents> asChunkedBodyContents() throws IOException { markConsumed(); return super.asChunkedBodyContents(); }