One Hundred and Fifty-Three

  • Random
  • Archive
  • RSS
  • Ask me anything

How to bloody well make sure you read the entire goddamn InputStream from an HTTPExchange.requestBody

let stream = htex.getRequestBody(),
    buf = new java.lang.StringBuilder(),
    read = -1,
    bytes;

do {
    bytes = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, stream.available());
    read = stream.read(bytes);
    buf.append(new java.lang.String(bytes));
} while(read != -1);

stream.close();

Took me hours to figure out it wasn’t reading the whole thing in the first place.

  • 6 months ago
  • Comments
  • Permalink
  • Share
    Tweet

Recent comments

Blog comments powered by Disqus
← Previous • Next →

About

Avatar 153 Ways That Things Can Go Wrong and Then Awesomely Right, or Inventive Solutions to Problems That Don't Exist

Me, Elsewhere

  • Facebook Profile
  • quartertotomorrow on Flickr
  • mattyb1000 on Last.fm
  • Google
  • quarterto on github

Following

Cool Shit

See more →
  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr