minor code clean-up BLD200503101100
authorthurka@netbeans.org
Thu, 24 Feb 2005 17:06:01 +0000
changeset 1665abf774742624
parent 1664 79270a45ef2d
child 1666 aae45494a43b
minor code clean-up
mdr/src/org/netbeans/mdr/util/IOUtils.java
     1.1 --- a/mdr/src/org/netbeans/mdr/util/IOUtils.java	Tue Feb 22 13:40:13 2005 +0000
     1.2 +++ b/mdr/src/org/netbeans/mdr/util/IOUtils.java	Thu Feb 24 17:06:01 2005 +0000
     1.3 @@ -77,18 +77,18 @@
     1.4       * 3 bytes, little-endian and other values as 5 bytes, little-endian
     1.5       */
     1.6      public static void writeInt(OutputStream outputStream, int val) throws IOException {
     1.7 -        if ((int) ((byte) val & 0x7F) == val) {
     1.8 +        if ((val & 0x7F) == val) {
     1.9              outputStream.write((byte)val);
    1.10          } else {
    1.11              byte [] arr = new byte [5];
    1.12 -            arr[1] = (byte)(val & 0xff);
    1.13 -            arr[2] = (byte)((val & 0xff00) >>> 8);
    1.14 -            if ((int) ((byte) (val >>> 8) & 0xFF) == val >>> 8) {
    1.15 +            arr[1] = (byte)val;
    1.16 +            arr[2] = (byte)(val >>> 8);
    1.17 +            if ((val >>> 16) == 0) {
    1.18                  arr[0] = (byte)(T_SHORT | 0x80);
    1.19                  outputStream.write(arr, 0, 3);
    1.20              } else {
    1.21 -                arr[3] = (byte)((val & 0xff0000) >>> 16);
    1.22 -                arr[4] = (byte)((val >>> 24) & 0xff);
    1.23 +                arr[3] = (byte)(val >>> 16);
    1.24 +                arr[4] = (byte)(val >>> 24);
    1.25                  arr[0] = (byte)(T_INTEGER | 0x80);
    1.26                  outputStream.write(arr, 0, 5);
    1.27              }
    1.28 @@ -100,24 +100,24 @@
    1.29      }
    1.30      
    1.31      public static void writeLong(OutputStream outputStream, long val) throws IOException {
    1.32 -        if ((int) ((byte) val & 0x7F) == val) {
    1.33 +        if ((val & 0x7F) == val) {
    1.34              outputStream.write((byte)val);
    1.35 -        } else if ((int) ((byte) (val >>> 24) & 0xFF) == val >>> 24) {
    1.36 +        } else if ((val >>> 32) == 0) {
    1.37              outputStream.write(T_INTEGER | 0x80);
    1.38 -            outputStream.write((byte)(val & 0xff));
    1.39 -            outputStream.write((byte)((val & 0xff00) >>> 8));
    1.40 -            outputStream.write((byte)((val & 0xff0000) >>> 16));
    1.41 -            outputStream.write((byte)((val >>> 24) & 0xff));
    1.42 +            outputStream.write((byte)val);
    1.43 +            outputStream.write((byte)(val >>> 8));
    1.44 +            outputStream.write((byte)(val >>> 16));
    1.45 +            outputStream.write((byte)(val >>> 24));
    1.46          } else {
    1.47              outputStream.write(T_LONG | 0x80);
    1.48 -            outputStream.write((byte)(val & 0xff));
    1.49 -            outputStream.write((byte)((val & 0xff00) >>> 8));
    1.50 -            outputStream.write((byte)((val >>> 16) & 0xff));
    1.51 -            outputStream.write((byte)((val >>> 24) & 0xff));
    1.52 -            outputStream.write((byte)((val >>> 32) & 0xff));
    1.53 -            outputStream.write((byte)((val >>> 40) & 0xff));
    1.54 -            outputStream.write((byte)((val >>> 48) & 0xff));
    1.55 -            outputStream.write((byte)((val >>> 56) & 0xff));
    1.56 +            outputStream.write((byte)val);
    1.57 +            outputStream.write((byte)(val >>> 8));
    1.58 +            outputStream.write((byte)(val >>> 16));
    1.59 +            outputStream.write((byte)(val >>> 24));
    1.60 +            outputStream.write((byte)(val >>> 32));
    1.61 +            outputStream.write((byte)(val >>> 40));
    1.62 +            outputStream.write((byte)(val >>> 48));
    1.63 +            outputStream.write((byte)(val >>> 56));
    1.64          }
    1.65      }
    1.66      
    1.67 @@ -317,11 +317,8 @@
    1.68          return (byte)is.read();
    1.69      }
    1.70      
    1.71 -    public static int readInt(InputStream is) throws IOException {
    1.72 -        return readInt(is, is.read());
    1.73 -    }
    1.74 -    
    1.75 -    static int readInt(InputStream inputStream, int type) throws IOException {
    1.76 +    public static int readInt(InputStream inputStream) throws IOException {
    1.77 +        int type = inputStream.read();
    1.78          if (type <= 0x7f)
    1.79              return type;
    1.80          switch (type) {
    1.81 @@ -337,7 +334,7 @@
    1.82                  ch2 = inputStream.read();
    1.83                  ch3 = inputStream.read();
    1.84                  ch4 = inputStream.read();
    1.85 -                return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + ch1;
    1.86 +                return (ch4 << 24) | (ch3 << 16) | (ch2 << 8) | ch1;
    1.87              }
    1.88              default:
    1.89                  throw new IOException("Unknown int format: " + type);
    1.90 @@ -355,10 +352,10 @@
    1.91                  ch2 = inputStream.read();
    1.92                  ch3 = inputStream.read();
    1.93                  ch4 = inputStream.read();
    1.94 -                return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + ch1;
    1.95 +                return (ch4 << 24) | (ch3 << 16) | (ch2 << 8) | ch1;
    1.96              }
    1.97              case T_LONG | 0x80: {
    1.98 -                long ch1, ch2, ch3, ch4;
    1.99 +                int ch1, ch2, ch3, ch4;
   1.100                  long v_low,v_high;
   1.101                  
   1.102                  ch1 = inputStream.read();
   1.103 @@ -371,7 +368,7 @@
   1.104                  ch3 = inputStream.read();
   1.105                  ch4 = inputStream.read();
   1.106                  v_high = ((ch4 << 24) | (ch3 << 16) | (ch2 << 8) | ch1);
   1.107 -                return (v_high << 32) | v_low;
   1.108 +                return (v_high << 32) | (v_low & 0xFFFFFFFFL);
   1.109              }
   1.110              default:
   1.111                  throw new IOException("Unknown int format: " + t);