commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject cvs commit: jakarta-commons-sandbox/io/src/java/org/apache/commons/io EndianUtils.java
Date Thu, 27 Nov 2003 04:07:10 GMT
bayard      2003/11/26 20:07:09

  Modified:    io/src/java/org/apache/commons/io EndianUtils.java
  Log:
  The byte array element when shifted is only in an 'int' scope I believe,
  so when it's shifted by more than 24, it goes off the end.
  
  My solution is to break in two parts and then shift them on top once they're
  in a long scope.
  
  Revision  Changes    Path
  1.6       +10 -7     jakarta-commons-sandbox/io/src/java/org/apache/commons/io/EndianUtils.java
  
  Index: EndianUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/EndianUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EndianUtils.java	27 Nov 2003 02:58:10 -0000	1.5
  +++ EndianUtils.java	27 Nov 2003 04:07:09 -0000	1.6
  @@ -250,14 +250,17 @@
        */
       public static long readSwappedLong( final byte[] data, final int offset )
       {
  -        return (long)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
  +        long ln = (long)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) );
  +        long low = (long)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
               ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
               ( ( data[ offset + 2 ] & 0xff ) << 16 ) +
  -            ( ( data[ offset + 3 ] & 0xff ) << 24 ) +
  -            ( ( data[ offset + 4 ] & 0xff ) << 32 ) +
  -            ( ( data[ offset + 5 ] & 0xff ) << 40 ) +
  -            ( ( data[ offset + 6 ] & 0xff ) << 48 ) +
  -            ( ( data[ offset + 7 ] & 0xff ) << 56 ) );
  +            ( ( data[ offset + 3 ] & 0xff ) << 24 ) );
  +        long high = (long)(
  +            ( ( data[ offset + 4 ] & 0xff ) << 0 ) +
  +            ( ( data[ offset + 5 ] & 0xff ) << 8 ) +
  +            ( ( data[ offset + 6 ] & 0xff ) << 16 ) +
  +            ( ( data[ offset + 7 ] & 0xff ) << 24 ) );
  +        return low + (high << 32);
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message