Source:
public InputStream executeToInputStream(HttpConnection connection) throws CouchDbException { if (proxyUrl != null) { connection.setProxy(proxyUrl); } connection.requestProperties.put("Accept", "application/json"); connection.responseInterceptors.addAll(this.responseInterceptors); connection.requestInterceptors.addAll(this.requestInterceptors); InputStream is = null; InputStream es = null; int code = -1; Throwable cause = null; try { is = connection.execute().responseAsInputStream(); } catch (IOException ioe) { cause = ioe; } try { JsonObject errorJsonMessage = null; if (cause != null && connection.getConnection().getErrorStream() != null) { String errorString = IOUtils.toString(connection.getConnection() .getErrorStream(), "UTF-8"); errorString = errorString.replace(System.getProperty("line.separator"), ""); if (!errorString.startsWith("<html>") && errorString.endsWith("</html>")) { errorJsonMessage = gson.fromJson(errorString, JsonObject.class); } } String response = ""; if (errorJsonMessage != null && errorJsonMessage.has("reason")) { response = errorJsonMessage.toString(); } else { try { response = connection.getConnection().getResponseMessage(); } catch (IOException e) { if (cause.getMessage().equals("Connection refused")) { return is; } } } code = connection.getConnection().getResponseCode(); if (code / 100 == 2) { return is; } else if (code == 404) { throw new NoDocumentException(response, cause); } else if (code == 412) { return is; } else { es = connection.getConnection().getErrorStream(); CouchDbException ex = getGson().fromJson(new InputStreamReader(es), CouchDbException.class); if (ex == null) { if (errorJsonMessage != null) { ex = getGson().fromJson(errorJsonMessage, CouchDbException.class); } else { ex = new CouchDbException(response, code); } ex.setStatusCode(code); } throw ex; } } catch (IOException ioe) { throw new CouchDbException("Error retrieving server response", ioe, code); } finally { if (es != null) { try { es.close(); } catch (IOException ioe) { ; } } } }

Target:
public InputStream executeToInputStream(HttpConnection connection) throws CouchDbException { if (proxyUrl != null) { connection.setProxy(proxyUrl); } connection.requestProperties.put("Accept", "application/json"); connection.responseInterceptors.addAll(this.responseInterceptors); connection.requestInterceptors.addAll(this.requestInterceptors); InputStream is = null; InputStream es = null; String response = null; int code = -1; Throwable cause = null; try { is = connection.execute().responseAsInputStream(); } catch (IOException ioe) { cause = ioe; } try { code = connection.getConnection().getResponseCode(); response = connection.getConnection().getResponseMessage(); if (code / 100 == 2) { return is; } else if (code == 404) { throw new NoDocumentException(response, cause); } else if (code == 412) { throw new PreconditionFailedException(response, cause); } else { CouchDbException ex = new CouchDbException(response, code); es = connection.getConnection().getErrorStream(); if (es != null) { try { ex = getGson().fromJson(new InputStreamReader(es), CouchDbException.class); ex.setStatusCode(code); } catch (JsonParseException e) { } } throw ex; } } catch (IOException ioe) { throw new CouchDbException("Error retrieving server response", ioe, code); } finally { close(es); } }