tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ed Korthof ...@apache.org>
Subject Re: Ajpv12InputStream.java bit op dillema
Date Fri, 02 Jun 2000 23:35:27 GMT
On Fri, 2 Jun 2000, M. Greenblatt wrote:

> Ed-
> 
> Since read() is required to return an int between 0 and 255 why is it
> necessary to check that this value is positive? Shouldn't we be doing
> something like:
> 
> 
>        byte bytes[] = new byte[2];
> 
>        if (read(bytes, 0, 2) != 2)
>            return -1;
> 
>        return (bytes[0] << 8) | bytes[1];

This version of read (read(byte[],int,int)) operates differently: it reads
bytes, *not* integers.  When I wrote a test program, the JVM treated them
as signed bytes.

> And submit a bug report to the JVM developer if we're getting signed
> bytes? ;-)
> 
> Also, it's not necissary to explicitly cast byte to int (though it
> doesn't hurt). Finally, you might want to test if -bytes[0] is faster
> than bytes[0] + 256.

Unfortunately, that produces a different result: 
        -10 + 256 == 246
        -(-10)    == 10

The method I showed yields identical results to the previous JServ method,
where as -bytes[i] wouldn't ... this is because of how signed values are
implemented.

thanks --

Ed


Mime
View raw message