@Override public Void convert(ResponseBody value) { value.close(); return null; } }
@Override public Unit convert(ResponseBody value) { value.close(); return Unit.INSTANCE; } }
@Override public void close() { delegate.close(); }
@Override public void close() { ResponseBody body = this.response.body(); if (body != null) { body.close(); } }
/** * Closes the response body. Equivalent to {@code body().close()}. * * <p>It is an error to close a response that is not eligible for a body. This includes the * responses returned from {@link #cacheResponse}, {@link #networkResponse}, and {@link * #priorResponse()}. */ @Override public void close() { if (body == null) { throw new IllegalStateException("response is not eligible for a body and must not be closed"); } body.close(); }
@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(); } } }
public void run() throws Exception { Request request = new Request.Builder() .url("https://publicobject.com/helloworld.txt") .build(); Response response = client.newCall(request).execute(); response.body().close(); }
@Override public void cleanup() { try { if (stream != null) { stream.close(); } } catch (IOException e) { // Ignored } if (responseBody != null) { responseBody.close(); } callback = null; }
@Override public ResponseBody convert(ResponseBody value) throws IOException { try { // Buffer the entire body to avoid future I/O. return Utils.buffer(value); } finally { value.close(); } } }
@Override public T convert(ResponseBody value) throws IOException { try { return adapter.decode(value.source()); } 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 { 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(); } } }
@Override public void close() { ResponseBody body = this.response.body(); if (body != null) { body.close(); } }
/** * Closes the current connection quietly, if there is one. */ private void closeConnectionQuietly() { if (response != null) { Assertions.checkNotNull(response.body()).close(); response = null; } responseByteStream = null; }
@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 void close() { closed.set(true); super.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(); } } }
public T convert(ResponseBody value) throws IOException { try { return JSON.parseObject(value.bytes() , fastJsonConfig.getCharset() , type , fastJsonConfig.getParserConfig() , fastJsonConfig.getParseProcess() , JSON.DEFAULT_PARSER_FEATURE , fastJsonConfig.getFeatures() ); } catch (Exception e) { throw new IOException("JSON parse error: " + e.getMessage(), e); } finally { value.close(); } } }
@Override public T convert(ResponseBody value) throws IOException { BufferedSource source = value.source(); try { // Moshi has no document-level API so the responsibility of BOM skipping falls to whatever // is delegating to it. Since it's a UTF-8-only library as well we only honor the UTF-8 BOM. if (source.rangeEquals(0, UTF8_BOM)) { source.skip(UTF8_BOM.size()); } JsonReader reader = JsonReader.of(source); T result = adapter.fromJson(reader); if (reader.peek() != JsonReader.Token.END_DOCUMENT) { throw new JsonDataException("JSON document was not fully consumed."); } return result; } finally { value.close(); } } }