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

How to use
contentType
method
in
okhttp3.ResponseBody

Best Java code snippets using okhttp3.ResponseBody.contentType (Showing top 20 results out of 1,395)

origin: square/retrofit

@Override public MediaType contentType() {
 return delegate.contentType();
}
origin: square/okhttp

@Override public MediaType contentType() {
 return responseBody.contentType();
}
origin: facebook/stetho

@Override
public MediaType contentType() {
 return mBody.contentType();
}
origin: commonsguy/cw-omnibus

@Override
public MediaType contentType() {
 return(wrapped.contentType());
}
origin: commonsguy/cw-omnibus

@Override
public MediaType contentType() {
 return(wrapped.contentType());
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public MediaType contentType() {
  return mResponseBody.contentType();
}
origin: Piasy/BigImageViewer

@Override
public MediaType contentType() {
  return mResponseBody.contentType();
}
origin: com.squareup.retrofit2/retrofit

@Override public MediaType contentType() {
 return delegate.contentType();
}
origin: Naoki2015/CircleDemo

@Override
public MediaType contentType() {
  return responseBody.contentType();
}
origin: JessYanCoding/ProgressManager

@Override
public MediaType contentType() {
  return mDelegate.contentType();
}
origin: LuckyJayce/LargeImage

@Override
public MediaType contentType() {
  return responseBody.contentType();
}
origin: square/okhttp

private Charset charset() {
 MediaType contentType = contentType();
 return contentType != null ? contentType.charset(UTF_8) : UTF_8;
}
origin: square/retrofit

static ResponseBody buffer(final ResponseBody body) throws IOException {
 Buffer buffer = new Buffer();
 body.source().readAll(buffer);
 return ResponseBody.create(body.contentType(), body.contentLength(), buffer);
}
origin: com.squareup.okhttp3/okhttp

private Charset charset() {
 MediaType contentType = contentType();
 return contentType != null ? contentType.charset(UTF_8) : UTF_8;
}
origin: prestodb/presto

public static <T> JsonResponse<T> execute(JsonCodec<T> codec, OkHttpClient client, Request request)
{
  try (Response response = client.newCall(request).execute()) {
    // TODO: fix in OkHttp: https://github.com/square/okhttp/issues/3111
    if ((response.code() == 307) || (response.code() == 308)) {
      String location = response.header(LOCATION);
      if (location != null) {
        request = request.newBuilder().url(location).build();
        return execute(codec, client, request);
      }
    }
    ResponseBody responseBody = requireNonNull(response.body());
    String body = responseBody.string();
    if (isJson(responseBody.contentType())) {
      return new JsonResponse<>(response.code(), response.message(), response.headers(), body, codec);
    }
    return new JsonResponse<>(response.code(), response.message(), response.headers(), body);
  }
  catch (IOException e) {
    // OkHttp throws this after clearing the interrupt status
    // TODO: remove after updating to Okio 1.15.0+
    if ((e instanceof InterruptedIOException) && "thread interrupted".equals(e.getMessage())) {
      Thread.currentThread().interrupt();
    }
    throw new UncheckedIOException(e);
  }
}
origin: com.squareup.retrofit2/retrofit

static ResponseBody buffer(final ResponseBody body) throws IOException {
 Buffer buffer = new Buffer();
 body.source().readAll(buffer);
 return ResponseBody.create(body.contentType(), body.contentLength(), buffer);
}
origin: square/okhttp

/**
 * Peeks up to {@code byteCount} bytes from the response body and returns them as a new response
 * body. If fewer than {@code byteCount} bytes are in the response body, the full response body is
 * returned. If more than {@code byteCount} bytes are in the response body, the returned value
 * will be truncated to {@code byteCount} bytes.
 *
 * <p>It is an error to call this method after the body has been consumed.
 *
 * <p><strong>Warning:</strong> this method loads the requested bytes into memory. Most
 * applications should set a modest limit on {@code byteCount}, such as 1 MiB.
 */
public ResponseBody peekBody(long byteCount) throws IOException {
 BufferedSource peeked = body.source().peek();
 Buffer buffer = new Buffer();
 peeked.request(byteCount);
 buffer.write(peeked, Math.min(byteCount, peeked.getBuffer().size()));
 return ResponseBody.create(body.contentType(), buffer.size(), buffer);
}
origin: openzipkin/brave

/** like {@link #get(Request)} except doesn't throw unsupported on not found */
Response call(Request request) throws IOException {
 try (Response response = client.newCall(request).execute()) {
  if (!HttpHeaders.hasBody(response)) return response;
  // buffer response so tests can read it. Otherwise the finally block will drop it
  ResponseBody toReturn;
  try (ResponseBody body = response.body()) {
   Buffer buffer = new Buffer();
   body.source().readAll(buffer);
   toReturn = ResponseBody.create(body.contentType(), body.contentLength(), buffer);
  }
  return response.newBuilder().body(toReturn).build();
 }
}
origin: square/okhttp

public void processResponse(Response response) {
 try {
  if (!response.isSuccessful()) {
   listener.onFailure(this, null, response);
   return;
  }
  ResponseBody body = response.body();
  //noinspection ConstantConditions main body is never null
  MediaType contentType = body.contentType();
  if (!isEventStream(contentType)) {
   listener.onFailure(this,
     new IllegalStateException("Invalid content-type: " + contentType), response);
   return;
  }
  // Replace the body with an empty one so the callbacks can't see real data.
  response = response.newBuilder().body(Util.EMPTY_RESPONSE).build();
  ServerSentEventReader reader = new ServerSentEventReader(body.source(), this);
  try {
   listener.onOpen(this, response);
   while (reader.processNextEvent()) {
   }
  } catch (Exception e) {
   listener.onFailure(this, e, response);
   return;
  }
  listener.onClosed(this);
 } finally {
  response.close();
 }
}
origin: square/retrofit

.body(new NoContentResponseBody(rawBody.contentType(), rawBody.contentLength()))
.build();
okhttp3ResponseBodycontentType

Popular methods of ResponseBody

  • string
    Returns the response as a string decoded with the charset of the Content-Type header. If that header
  • byteStream
  • source
  • 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

  • Creating JSON documents from java classes using gson
  • runOnUiThread (Activity)
  • getApplicationContext (Context)
  • addToBackStack (FragmentTransaction)
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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