title: Sending binary data with HttpURLConnection
body: <p>i want to use google speech api, i've found this <a href="https://github.com/gillesdemey/google-speech-v2/" rel="nofollow">https://github.com/gillesdemey/google-speech-v2/</a> where everything is explained well, but and im trying to rewrite it into java.</p>
  
  <pre><code>File filetosend = new File(path);
  byte[] bytearray = Files.readAllBytes(filetosend);
  URL url = new URL("https://www.google.com/speech-api/v2/recognize?output="+outputtype+"&amp;lang="+lang+"&amp;key="+key);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  //method
  conn.setRequestMethod("POST");
  //header
  conn.setRequestProperty("Content-Type", "audio/x-flac; rate=44100");
  </code></pre>
  
  <p>now im lost... i guess i need to add the bytearray into the request. in the example its line </p>
  
  <pre><code>--data-binary @audio/good-morning-google.flac \
  </code></pre>
  
  <p>but httpurlconnection class has no method for attaching binary data.</p>