We have a problem returning a stream from a java servlet to a VB application. The problem seems to be related to java using signed bytes while VB uses unsigned bytes. If the stream returned by the java servlet only contains bytes with values from 0 to 128, it works perfectly. However if the stream contains bytes with negative number values, the stream that VB receives? is very different to the stream that java sends - different stream lengths, different byte values, etc. There is no obvious correspondence where a? particular negative number? sent by java always ends up as a particular number in VB. There doesn't even seem to be any correspondence in the stream lengths -? one stream of length 39 sent from java ends up as a stream of length 70 in VB, whereas a different stream of length 39 sent from? java ends up as a stream of a different length in VB.
I have attached a simple test app that replicates the problem.? The VB app sends an array of bytes to the? java servlet. The? java servlet reads the input and returns it to the? VB app. You can? change the array of bytes the VB app is? sending? to see how the stream being sent back from the java servlet varies. Note it always seems to add 13 and 10 at the end.
I could fix this by? multiplying all of the negative number bytes in? java by -1 and adding extra bytes to the stream to indicate which bytes should be negative and which shouldn't, then converting everything back? once its received in VB. However our real application is sending large amounts of data and I don't want to add this extra overhead.?
The job is to fix the attached? VB app and? java servlet? so that ? any byte array sent by the java servlet is correctly received by the VB app, without increasing the size of the stream.