@Override public T convert(ResponseBody value) throws IOException { try { return adapter.readValue(value.charStream()); } finally { value.close(); } } }
@Override public T convert(ResponseBody value) throws IOException { try { Unmarshaller unmarshaller = context.createUnmarshaller(); XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(value.charStream()); return unmarshaller.unmarshal(streamReader, type).getValue(); } catch (JAXBException | XMLStreamException e) { throw new RuntimeException(e); } finally { value.close(); } } }
/** * Get stream of characters, decoded with the charset * of the Content-Type header. If that header is either absent or lacks a * charset, this will attempt to decode the response body as UTF-8. */ @Override public Reader contentReader() { return okResponse.body().charStream(); }
@Override public T convert(ResponseBody value) throws IOException { try { T read = serializer.read(cls, value.charStream(), strict); if (read == null) { throw new IllegalStateException("Could not deserialize body as " + cls); } return read; } catch (RuntimeException | IOException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } finally { value.close(); } } }
@Override public T convert(ResponseBody value) throws IOException { try { return adapter.readValue(value.charStream()); } finally { value.close(); } }
@Override public T convert(ResponseBody value) throws IOException { JsonReader jsonReader = gson.newJsonReader(value.charStream()); try { T result = adapter.read(jsonReader); if (jsonReader.peek() != JsonToken.END_DOCUMENT) { throw new JsonIOException("JSON document was not fully consumed."); } return result; } finally { value.close(); } } }
@Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()) { Reader in=response.body().charStream(); BufferedReader reader=new BufferedReader(in); final SOQuestions questions= new Gson().fromJson(reader, SOQuestions.class); reader.close(); view.post(new Runnable() { @Override public void run() { setListAdapter(new ItemsAdapter(questions.items)); } }); } else { Log.e(getClass().getSimpleName(), response.toString()); } } });
@Override public void run() { try { Request request=new Request.Builder().url(SO_URL).build(); Response response=client.newCall(request).execute(); final SOQuestions result= new Gson().fromJson(response.body().charStream(), SOQuestions.class); runOnUiThread(new Runnable() { @Override public void run() { setListAdapter(new ItemsAdapter(result.items)); } }); } catch (IOException e) { onConnectionException(e); } } }.start();
@Override public void run() { try { OkHttpClient client=new OkHttpClient(); Request request=new Request.Builder().url(SO_URL).build(); Response response=client.newCall(request).execute(); if (response.isSuccessful()) { Reader in=response.body().charStream(); BufferedReader reader=new BufferedReader(in); rawResult=new Gson().fromJson(reader, SOQuestions.class); reader.close(); EventBus .getDefault() .post(new ThingsLoadedEvent(QuestionsLoader.this)); } else { Log.e(getClass().getSimpleName(), response.toString()); } } catch (Exception e) { Log.e(getClass().getSimpleName(), "Exception parsing JSON", e); } } }
@Override public void onResponse(Call call, Response response) throws IOException { Reader in=response.body().charStream(); BufferedReader reader=new BufferedReader(in); SOQuestions questions=new Gson().fromJson(reader, SOQuestions.class); reader.close(); if (getActivity()!=null && !getActivity().isDestroyed()) { getActivity().runOnUiThread(() -> setListAdapter(new ItemsAdapter(questions.items))); } } });
@Override public T convert(ResponseBody value) throws IOException { JsonReader jsonReader = gson.newJsonReader(value.charStream()); try { return adapter.read(jsonReader); } finally { value.close(); } } }
@Override public T convert(ResponseBody value) throws IOException { JsonReader jsonReader = gson.newJsonReader(value.charStream()); try { T result = adapter.read(jsonReader); if (jsonReader.peek() != JsonToken.END_DOCUMENT) { throw new JsonIOException("JSON document was not fully consumed."); } return result; } finally { value.close(); } } }
@Override public Converter<ResponseBody, ?> responseBodyConverter( Type type, Annotation[] annotations, Retrofit retrofit) { // This converter requires an annotation providing the name of the payload in the envelope; // if one is not supplied then return null to continue down the converter chain. final String payloadName = getPayloadName(annotations); if (payloadName == null) return null; final TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type)); return (Converter<ResponseBody, Object>) body -> { try (JsonReader jsonReader = gson.newJsonReader(body.charStream())) { jsonReader.beginObject(); while (jsonReader.hasNext()) { if (payloadName.equals(jsonReader.nextName())) { return adapter.read(jsonReader); } else { jsonReader.skipValue(); } } return null; } finally { body.close(); } }; }
/** * Returns an unclosed Reader. It's the caller responsibility to close it. * @return Reader */ @Override public Reader getLogReader(){ return doGetLog().charStream(); }
/** * Returns an unclosed Reader. It's the caller responsibility to close it. * @return Reader */ @Override public Reader getLogReader() { return doGetLog().charStream(); }
/** * Return a {@link JsonElement} representation of the response. * * @param response the Response * @return the content body as JSON */ public static JsonElement getJsonElement(Response response) { return new JsonParser().parse(response.body().charStream()); }
/** * Return a {@link JsonElement} representation of the response. * * @param response the Response * @return the content body as JSON */ public static JsonElement getJsonElement(Response response) { return new JsonParser().parse(response.body().charStream()); }
@Override public T convert(ResponseBody value) throws IOException { try { return adapter.readValue(value.charStream()); } finally { value.close(); } } }
@Override public <T> T handleError(Response response, Class<? extends T> clazz) throws OkRestException { OkRestException x = OkRestException.fromResponse(response); try { String s = CharStreams.toString(response.body().charStream()); x.setErrorResponseBody(s); } catch (Exception ignore) { // ignore this } throw x; }
@Override public T convert(ResponseBody value) throws IOException { TypeAdapter<T> adapter = getAdapter(); JsonReader jsonReader = gson.newJsonReader(value.charStream()); jsonReader.setLenient(true); try { return adapter.read(jsonReader); } finally { value.close(); } } }