Upload binary data to Java
<p>Thanks for any help with this:</p>

<p>I have the following C# code:</p>

<pre><code>double[] data = new double[] { 1.0, 2.0, 3.0 };

byte[] bytes = CreateByteArrayFromDoubleArray(data);

WebClient webClient = new WebClient();

byte[] byteData = webClient.UploadData(szWebEndPoint + "?double", bytes);
</code></pre>

<p>This calls the Java servlet code below:</p>

<pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        String szDoubleUp = request.getParameter("double");

        double[] doubles = {2.5,4.5,6.5,8.5};

        if(szDoubleUp != null &amp;&amp; szDoubleUp.equals("true"))
        {
            doubles[0] = 5.0;
        }

        byte[] bytes = new byte[doubles.length * 8];

        ByteBuffer buf = ByteBuffer.wrap(bytes);

        for (double d : doubles)
        {
            buf.putDouble(d);
        }

        response.setContentType("application/octet-stream");
        response.setContentLength(bytes.length);

        ServletOutputStream servletOutputStream = response.getOutputStream();

        servletOutputStream.write(bytes, 0, bytes.length);
        servletOutputStream.flush();
        servletOutputStream.close();
    }

}
</code></pre>

<p>And, as expected, this returns an array of numbers in C#, the first of which depends on the existence and value of request.getParameter("double")</p>

<p>But what about the array called data which I converted to bytes and set as the second parameter in my call to webClient.UploadData. How can I access these values in my Java servlet?</p>

<p>Could I use:</p>

<pre><code>InputStream inputStream = request.getInputStream();
</code></pre>

<p>But then how could I read the doubles out of here, I see that </p>

<pre><code>DataInputStream inputStream = request.getInputStream();
</code></pre>

<p>is not possible due to the following error:</p>

<p>"Type mismatch: cannot convert from ServletInputStream to DataInputStream"</p>

<p>So, my generic question is how can I read binary data sent from C# to Java servlet via WebClient.UploadData?</p>

<p>Thanks,
Mitch.</p>