/** * Consume the HTTP message body fully, excluding framing metadata. * <p> * For the {@link rawhttp.core.body.FramedBody.Chunked} frame, for example, this method returns only the actual * data which is wrapped into the chunks, but not the chunk-size, attributes and trailer-part. * * @param inputStream the raw input stream * @return the bytes of the data included in the message body * @throws IOException if an error occurs while consuming the message body */ public byte[] consumeData(InputStream inputStream) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); consumeDataInto(inputStream, out, DEFAULT_BUFFER_SIZE); return out.toByteArray(); }
/** * Consume the HTTP message body fully, excluding framing metadata. * <p> * For the {@link rawhttp.core.body.FramedBody.Chunked} frame, for example, this method returns only the actual * data which is wrapped into the chunks, but not the chunk-size, attributes and trailer-part. * * @param inputStream the raw input stream * @return the bytes of the data included in the message body * @throws IOException if an error occurs while consuming the message body */ public byte[] consumeData(InputStream inputStream) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); consumeDataInto(inputStream, out, DEFAULT_BUFFER_SIZE); return out.toByteArray(); }
/** * Read the HTTP message body, simultaneously unframing and decoding it, * then writing the decoded body 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 unframed, decoded message body to * @param bufferSize size of the buffer to use for writing, if possible * @throws IOException if an error occurs while writing the message * @throws UnknownEncodingException if the body is encoded with an encoding that is unknown * by the {@link HttpBodyEncodingRegistry}. */ public void writeDecodedTo(OutputStream out, int bufferSize) throws IOException { DecodingOutputStream decodedStream = framedBody.getBodyDecoder().decoding(out); framedBody.getBodyConsumer().consumeDataInto(asRawStream(), decodedStream, bufferSize); decodedStream.finishDecoding(); }
/** * Read the HTTP message body, simultaneously unframing and decoding it, * then writing the decoded body 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 unframed, decoded message body to * @param bufferSize size of the buffer to use for writing, if possible * @throws IOException if an error occurs while writing the message * @throws UnknownEncodingException if the body is encoded with an encoding that is unknown * by the {@link HttpBodyEncodingRegistry}. */ public void writeDecodedTo(OutputStream out, int bufferSize) throws IOException { DecodingOutputStream decodedStream = framedBody.getBodyDecoder().decoding(out); framedBody.getBodyConsumer().consumeDataInto(asRawStream(), decodedStream, bufferSize); decodedStream.finishDecoding(); }