title: Getting a HTTP POST binary payload to a byte array in Scala
body: <p>I have a socket which will persist for long. Client will keep streaming data requests to my server app through the socket. Request is a POST with a binary payload which needs to be copied to a byte array which i need to use to get the protocol buffer class.</p>
  
  <pre><code>POST / HTTP/1.1
  Host: 127.0.0.1:80
  Accept-Encoding: identity
  Content-Length: 423
  Content-type: application/octet-stream
  
  [PAYLOAD]
  
  val out = new DataOutputStream(socket.getOutputStream())
  val in = new BufferedReader(new InputStreamReader(socket.getInputStream()))
  </code></pre>
  
  <p>Any ideas ? </p>
  
  <p>UPDATE - I got a temporary solution using a DEPRECATED java function - DataInputStream.readLine.</p>
  
  <p>Can someone make this code better ?</p>
  
  <pre><code>val in = new DataInputStream(socket.getInputStream())
  var n:Int = 0
  var size:Int=0
  while (n==0) {
      var str=in.readLine
      if(str==""){
          n =1
      }else{
          val breaks=str.split(" ")
          if(breaks(0).equals("Content-Length:"))size=breaks(1).toInt
      }
  }
  var payload:Array[Byte]=new Array(size)
  n=size-1
  for(i &lt;- 0 to n) payload(i)=in.readByte
  </code></pre>