Just do this using Apache Commons IO: http://commons.apache.org/proper/commons-io/
private byte[] receiveByteArrayData(HttpURLConnection httpURLConnection)
throws IOException
{
return IOUtils.toByteArray(httpURLConnection.getInputStream());
}
Sending byte[]
data:
URL url = new URL("http://your.url.here:yourPortNumber/something");
HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
httpUrlConnection.setDoInput(true);
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setRequestProperty("Content-Type", "application/octet-stream");
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.setFixedLengthStreamingMode(bytes.length);
httpUrlConnection.connect();
httpUrlConnection.getOutputStream().write(bytes);
httpUrlConnection.getOutputStream().flush();
if (httpsUrlConnection.getResponseCode() == 200) //OK
{
System.out.println("successfully uploaded data");
}
httpUrlConnection.disconnect();