Remember all available() tells you is the number of bytes that are available to be read (i.e have arrived) at the time you ask. Whether or not the number of bytes returned by available() corresponds to the total size of the data stream is purely co-incidental. Over TCP you have no idea how many bytes are going to arrive together or when. So what you need to do is something like this;
1) Allocate a byte array to the size of the largest possible message. If you can't do this, then you will need to be able to grow you storage array via System.arraycopy.
2) Loop
and store bytes into buffer. When available returns 0 then either the server has finished sending or there are still bytes "in-transit" - you've no way of telling. In this case, all you can do is sleep() for an amount of time appropriate for your application and then
test available() again.
Note that even if you do know how long each message is going to be, you still need to loop like this, because there is no guarentee that all the bytes have actually arrived at the point in time when you call inputStream.read().
HTH