高手来给我解释解释这些代码是什么意思?    public static final short readShort(byte[] dis) {
        int firstByte  = dis[index++];
        int secondByte = dis[index++];
        return (short)((firstByte & 0x00ff) | (secondByte<<8));
    }
    
    public static final byte readByte(byte[] dis) {
        return (byte)(dis[index++] & 0xff);
    }    public static final int readInt(DataInputStream dis) throws IOException {
        int a = dis.read();
        int b = dis.read();
        int c = dis.read();
        int d = dis.read();        if ((a | b | c | d) < 0) {
            throw new EOFException();
        } else {
            return (d << 24) + (c << 16) + (b << 8) + (a << 0);
        }
    }    public static final char readChar(DataInputStream dis) throws IOException {
        int a = dis.read();
        int b = dis.read();
        if ((a | b) < 0) {
            throw new EOFException();
        } else {
            return (char) ((b << 8) + (a << 0));
        }
    }

解决方案 »

  1.   

    不是加密,
    是将二进制数据转换成Java的基本类型数据。
    我看,像是在网络通信或者文件存储等信息交互方面使用的代码。
    每个方法都不一样,感觉,应该不会出自同一个人编写的代码。
    因为,感觉,几个方法的应用场景不同。
      

  2.   

    首先,这个类不用该这么编写,index变量的类共享,使得该类无法在多线程中使用。
    其次,没有理解DataInputStream存在的意义,这样用法,真让人崩溃。    //将字节数组中index位值的顺延两字节的数据转换成short类型的数据。
        public static final short readShort(byte[] dis) {
            int firstByte  = dis[index++];
            int secondByte = dis[index++];
            return (short)((firstByte & 0x00ff) | (secondByte<<8));
        }
        //将字节数组中第index位置的一个字节的数据,转换成byte类型的数据。
        public static final byte readByte(byte[] dis) {
            return (byte)(dis[index++] & 0xff);
        }
        //从DataInputStream类对象中,按照一定的方式,读取一个整型的数据。
        //这个方式就是,将连续四个整型的数据,分别取低位字节,并凑成一个新的整型数据。
        public static final int readInt(DataInputStream dis) throws IOException {
            int a = dis.read();
            int b = dis.read();
            int c = dis.read();
            int d = dis.read();        if ((a | b | c | d) < 0) {
                throw new EOFException();
            } else {
                return (d << 24) + (c << 16) + (b << 8) + (a << 0);
            }
        }
        //从DataInputStream类对象中,按照一定的方式,读取一个字符的数据。
        //这个方式就是,将连续两个整型的数据,分别取低位字节,并凑成一个新的字符数据。
        public static final char readChar(DataInputStream dis) throws IOException {
            int a = dis.read();
            int b = dis.read();
            if ((a | b) < 0) {
                throw new EOFException();
            } else {
                return (char) ((b << 8) + (a << 0));
            }
        }