Skip to content
Browse files

fix FHttpRequest.asBytes conversion

asBytes now returns a bytebuffer with
the exact number of bytes necessary
  • Loading branch information...
1 parent 5649aa6 commit 147cd7ffcb98316d6c13b4488e869418afa4178f @slackhappy slackhappy committed
Showing with 6 additions and 1 deletion.
  1. +6 −1 src/main/scala/com/foursquare/fhttp/FHttpRequest.scala
View
7 src/main/scala/com/foursquare/fhttp/FHttpRequest.scala
@@ -50,7 +50,12 @@ object FHttpRequest {
/**
* Extracts the contents as a byte array
*/
- def asBytes: HttpResponse => Array[Byte] = res => res.getContent.toByteBuffer.array
+ def asBytes: HttpResponse => Array[Byte] = res => {
+ val buffer = res.getContent.toByteBuffer
+ val bytes = new Array[Byte](buffer.remaining)
+ buffer.get(bytes, buffer.arrayOffset, buffer.remaining)
+ bytes
+ }
/**
* Extracts the contents as an input stream

0 comments on commit 147cd7f

Please sign in to comment.
Something went wrong with that request. Please try again.