Database Reference
In-Depth Information
InputStreamReader is =
new InputStreamReader(conn.getInputStream(),
"UTF-8");
try {
StringBuilder builder = new StringBuilder();
char buffer[];
if (contentLength > 0) {
buffer = new char[contentLength];
} else {
buffer = new char[512];
}
int charsRead;
while ((charsRead = is.read(buffer)) > 0) {
builder.append(buffer, 0, charsRead);
}
return builder.toString();
} finally {
is.close();
}
} catch (IOException ex) {
throw new ErrorResult(ex);
}
}
// Wraps a HTTP error code and response body in an
ErrorResult object.
private JSONObject connectionError(int code, String
body) {
JSONObject result = new JSONObject();
try {
result.put("error", "ConnectionError");
result.put("message", String.format("Code = %d:
%s", code, body));
} catch (JSONException e) {
throw new RuntimeException(e);
}
return result;
Search WWH ::




Custom Search