Tabnine Logo
ResponseBody.byteStream
Code IndexAdd Tabnine to your IDE (free)

How to use
byteStream
method
in
okhttp3.ResponseBody

Best Java code snippets using okhttp3.ResponseBody.byteStream (Showing top 20 results out of 2,124)

origin: square/okhttp

 @Override
 public InputStream getBody() throws IOException {
  if (body == null) return null;
  return body.byteStream();
 }
};
origin: square/okhttp

 @Override
 public InputStream getBody() throws IOException {
  if (body == null) return null;
  return body.byteStream();
 }
};
origin: square/retrofit

 @Override public T convert(ResponseBody value) throws IOException {
  try {
   return parser.parseFrom(value.byteStream(), registry);
  } catch (InvalidProtocolBufferException e) {
   throw new RuntimeException(e); // Despite extending IOException, this is data mismatch.
  } finally {
   value.close();
  }
 }
}
origin: SonarSource/sonarqube

/**
 * Get stream of bytes
 */
@Override
public InputStream contentStream() {
 return okResponse.body().byteStream();
}
origin: spring-projects/spring-framework

@Override
public InputStream getBody() throws IOException {
  ResponseBody body = this.response.body();
  return (body != null ? body.byteStream() : StreamUtils.emptyInput());
}
origin: square/okhttp

@Override public InputStream getInputStream() throws IOException {
 if (!doInput) {
  throw new ProtocolException("This protocol does not support input");
 }
 Response response = getResponse(false);
 if (response.code() >= HTTP_BAD_REQUEST) {
  throw new FileNotFoundException(url.toString());
 }
 return response.body().byteStream();
}
origin: square/okhttp

/**
 * Returns an input stream from the server in the case of error such as the requested file (txt,
 * htm, html) is not found on the remote server.
 */
@Override public InputStream getErrorStream() {
 try {
  Response response = getResponse(true);
  if (HttpHeaders.hasBody(response) && response.code() >= HTTP_BAD_REQUEST) {
   return response.body().byteStream();
  }
  return null;
 } catch (IOException e) {
  return null;
 }
}
origin: lingochamp/okdownload

@Override public InputStream getInputStream() throws IOException {
  if (response == null) throw new IOException("Please invoke execute first!");
  final ResponseBody body = response.body();
  if (body == null) throw new IOException("no body found on response!");
  return body.byteStream();
}
origin: org.springframework/spring-web

@Override
public InputStream getBody() throws IOException {
  ResponseBody body = this.response.body();
  return (body != null ? body.byteStream() : StreamUtils.emptyInput());
}
origin: testcontainers/testcontainers-java

@Override
@SneakyThrows
public InputStream get() {
  Request request = requestBuilder
    .get()
    .build();
  return execute(request).body().byteStream();
}
origin: testcontainers/testcontainers-java

@Override
@SneakyThrows
public InputStream post(Object entity) {
  Request request = requestBuilder
    .post(RequestBody.create(MediaType.parse("application/json"), objectMapper.writeValueAsBytes(entity)))
    .build();
  return execute(request).body().byteStream();
}
origin: bumptech/glide

@Override
public void onResponse(@NonNull Call call, @NonNull Response response) {
 responseBody = response.body();
 if (response.isSuccessful()) {
  long contentLength = Preconditions.checkNotNull(responseBody).contentLength();
  stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength);
  callback.onDataReady(stream);
 } else {
  callback.onLoadFailed(new HttpException(response.message(), response.code()));
 }
}
origin: runelite/runelite

  @Override
  public void onResponse(Call call, Response response) throws IOException
  {
    try (ResponseBody responseBody = response.body())
    {
      if (!response.isSuccessful())
      {
        log.warn("Failed to download image " + item.getAvatar());
        return;
      }
      BufferedImage icon;
      synchronized (ImageIO.class)
      {
        icon = ImageIO.read(responseBody.byteStream());
      }
      avatar.setIcon(new ImageIcon(icon));
    }
  }
});
origin: biezhi/wechat-api

public <T extends ApiRequest, R extends ApiResponse> R download(final ApiRequest<T, R> request) {
  try {
    OkHttpClient client   = getOkHttpClient(request);
    Response     response = client.newCall(createRequest(request)).execute();
    return (R) new FileResponse(response.body().byteStream());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
origin: runelite/runelite

public Configuration get() throws IOException
{
  HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
    .addPathSegment("config")
    .build();
  logger.debug("Built URI: {}", url);
  Request request = new Request.Builder()
    .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString())
    .url(url)
    .build();
  try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
  {
    InputStream in = response.body().byteStream();
    return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), Configuration.class);
  }
  catch (JsonParseException ex)
  {
    throw new IOException(ex);
  }
}
origin: square/okhttp

private static HttpResponse transformResponse(Response response) {
 int code = response.code();
 String message = response.message();
 BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
 ResponseBody body = response.body();
 InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
 httpResponse.setEntity(entity);
 Headers headers = response.headers();
 for (int i = 0, size = headers.size(); i < size; i++) {
  String name = headers.name(i);
  String value = headers.value(i);
  httpResponse.addHeader(name, value);
  if ("Content-Type".equalsIgnoreCase(name)) {
   entity.setContentType(value);
  } else if ("Content-Encoding".equalsIgnoreCase(name)) {
   entity.setContentEncoding(value);
  }
 }
 return httpResponse;
}
origin: runelite/runelite

UUID open() throws IOException
{
  HttpUrl url = RuneLiteAPI.getApiRoot().newBuilder()
    .addPathSegment("session")
    .build();
  Request request = new Request.Builder()
    .url(url)
    .build();
  try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
  {
    ResponseBody body = response.body();
    
    InputStream in = body.byteStream();
    return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), UUID.class);
  }
  catch (JsonParseException | IllegalArgumentException ex) // UUID.fromString can throw IllegalArgumentException
  {
    throw new IOException(ex);
  }
}
origin: TeamNewPipe/NewPipe

public InputStream stream(String siteUrl) throws IOException {
  try {
    return getBody(siteUrl, Collections.emptyMap()).byteStream();
  } catch (ReCaptchaException e) {
    throw new IOException(e.getMessage(), e.getCause());
  }
}
origin: JessYanCoding/MVPArms

@Override
public void onResponse(@NonNull Call call, @NonNull Response response) {
  responseBody = response.body();
  if (response.isSuccessful()) {
    long contentLength = Preconditions.checkNotNull(responseBody).contentLength();
    stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength);
    callback.onDataReady(stream);
  } else {
    callback.onLoadFailed(new HttpException(response.message(), response.code()));
  }
}
origin: SonarSource/sonarqube

private void assertIsPomPomResponse(Response response) throws IOException {
 assertThat(response.code()).isEqualTo(200);
 assertThat(IOUtils.toString(response.body().byteStream())).isEqualTo("ok");
}
okhttp3ResponseBodybyteStream

Popular methods of ResponseBody

  • string
    Returns the response as a string decoded with the charset of the Content-Type header. If that header
  • source
  • contentType
  • contentLength
    Returns the number of bytes in that will returned by #bytes, or #byteStream, or -1 if unknown.
  • close
  • bytes
    Returns the response as a byte array.This method loads entire response body into memory. If the resp
  • create
    Returns a new response body that transmits content.
  • charStream
    Returns the response as a character stream decoded with the charset of the Content-Type header. If t
  • charset
  • getClass

Popular in Java

  • Making http post requests using okhttp
  • runOnUiThread (Activity)
  • setScale (BigDecimal)
  • findViewById (Activity)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • JLabel (javax.swing)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now