Created
April 25, 2011 23:01
-
-
Save Pretz/941444 to your computer and use it in GitHub Desktop.
WTF Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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