> At the time I'm using InputStream.read() method to read the first byte
> and to trigger InputStream.available() to find out how many bytes the
> buffer still contains before I read them all.
Don't use InputStream.available(). Instead, keep reading from the input
stream until it returns a value of -1 (EOF).
<snip>
> How can I ensure that InputStream.available() gives me the real number
> of bytes? Is it mandatory to add some kind of delay?
No, and there's no way to know for sure. Your best bet is to read data
from the input stream and write that data to an instance of
ByteArrayOutputStream. Then, when you've finished, you can retrieve that
data as an array of bytes from the ByteArrayOutputStream. Here's an
example of how to do it:
public byte[] readData(InputStream istream) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new buffer[4096];
int read = istream.read(buffer);
while(read != -1)
{
baos.write(buffer,0,read);
read = istream.read(buffer);
}
return baos.toByteArray();
}
HTH

Signature
Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard