Skip to content

Instantly share code, notes, and snippets.

@Pretz
Created April 25, 2011 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pretz/941444 to your computer and use it in GitHub Desktop.
Save Pretz/941444 to your computer and use it in GitHub Desktop.
WTF Java
int contentLength = 0;
if (request.containsHeader("content-length")) {
contentLength = Integer.parseInt(request.getFirstHeader("content-length").getValue());
}
String bodyString = null;
if (contentLength > 0) {
BasicHttpEntityEnclosingRequest req = new BasicHttpEntityEnclosingRequest(request.getRequestLine());
try {
conn.receiveRequestEntity(req);
} catch (HttpException e) {
Log.e(TAG, "Error reading HTTP entity", e);
return response;
}
HttpEntity body = req.getEntity();
InputStreamReader readTime = new InputStreamReader(body.getContent(), HTTP.UTF_8);
CharBuffer buff = CharBuffer.allocate(contentLength);
int total = 0;
while (total < contentLength) {
int read = readTime.read(buff);
if (read < 0) {
break;
}
total += read;
}
bodyString = buff.rewind().toString();
body.consumeContent();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment