Codota Logo
BodyReader.asRawStream
Code IndexAdd Codota to your IDE (free)

How to use
asRawStream
method
in
rawhttp.core.body.BodyReader

Best Java code snippets using rawhttp.core.body.BodyReader.asRawStream (Showing top 12 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * @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());
}
origin: renatoathaydes/rawhttp

/**
 * @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());
}
origin: renatoathaydes/rawhttp

/**
 * @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());
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * @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());
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * 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);
}
origin: renatoathaydes/rawhttp

/**
 * 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);
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * 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();
  }
}
origin: renatoathaydes/rawhttp

/**
 * 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();
  }
}
origin: renatoathaydes/rawhttp

public RawHttpResponse<CloseableHttpResponse> send(RawHttpRequest request) throws IOException {
  RequestBuilder builder = RequestBuilder.create(request.getMethod());
  builder.setUri(request.getUri());
  builder.setVersion(toProtocolVersion(request.getStartLine().getHttpVersion()));
  request.getHeaders().getHeaderNames().forEach((name) ->
      request.getHeaders().get(name).forEach(value ->
          builder.addHeader(new BasicHeader(name, value))));
  request.getBody().ifPresent(b -> builder.setEntity(new InputStreamEntity(b.asRawStream())));
  CloseableHttpResponse response = httpClient.execute(builder.build());
  RawHttpHeaders headers = readHeaders(response);
  StatusLine statusLine = adaptStatus(response.getStatusLine());
  @Nullable LazyBodyReader body;
  if (response.getEntity() != null) {
    FramedBody framedBody = http.getFramedBody(statusLine, headers);
    body = new LazyBodyReader(framedBody, response.getEntity().getContent());
  } else {
    body = null;
  }
  return new RawHttpResponse<>(response, request, statusLine, headers, body);
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * 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();
}
origin: renatoathaydes/rawhttp

/**
 * 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();
}
origin: renatoathaydes/rawhttp

InputStream responseStream = response.getBody().map(b -> b.isChunked() ? b.asRawStream() : null)
    .orElseThrow(() ->
        new IllegalStateException("HTTP response does not contain a chunked body"));
rawhttp.core.bodyBodyReaderasRawStream

Popular methods of BodyReader

  • writeTo
    Read the raw HTTP message body, simultaneously writing it to the given output. This method may not
  • asChunkedBodyContents
  • asRawBytes
  • close
  • decodeBody
    Unframe and decode the HTTP message's body.
  • eager
  • writeDecodedTo
    Read the HTTP message body, simultaneously unframing and decoding it, then writing the decoded body
  • asChunkStream
    Get a lazy stream of chunks if the message body is chunked, or empty otherwise. The last chunk is a
  • decodeBodyToString
    Unframe and decode the HTTP message's body, then turn it into a String using the given charset.
  • getLengthIfKnown
  • isChunked
  • isChunked

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSupportFragmentManager (FragmentActivity)
  • compareTo (BigDecimal)
  • startActivity (Activity)
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • List (java.util)
    A List is a collection which maintains an ordering for its elements. Every element in the List has a
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now