> Hello
>
> I am reading bytes from a stream but some are cmoing back corrupt.
> Someonly return ex. 456.
I'm not sure what you mean by corrupt, but I think you mean that some times
your read returns fewer than 1024 bytes. Whether that's corrupt or not
depends on your application. if _fromGeneva is a socket it may simply mean
that you havn't received all of the data yet and that you need to read more.
> byte[] byteobj= new byte[1024] ;
> n = _fromGeneva.read(byteobj, 0 , 1024);
>
> if(n >= 1024)
> _errorMsg = new String(blah) ;
The new String () is unnecessary here. Just say _errorMsg = blah;
> else
> {
> /* I want to put up to n in a new byte. How would I transfer up to n
> efficienlty from byteobj into another byte so the data is not
> corrupted. After say 456 i get null bytes */
I think you mean you want to copy the bytes read into another array. You
can do that with:
byte [] result = new byte [n];
System.arraycopy (byteobj, 0, result, 0, n);
Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/