高手来给我解释解释这些代码是什么意思? 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));
}
}
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));
}
}
解决方案 »
- 求ibaits软件包
- 小弟新手,怎么用eclipse打开文件夹里的.java(.class)文件啊?
- 求高手画个二维数组内存分析图
- 超高分求解SWING+MSSQL银行自动结息思路
- 请教一个面试问题
- 用开源的htmlparser,怎么把网页中的script和style标签里面的内容去掉
- --“贪吃蛇“---的代码过来下!!
- 急!java1.2不能正常运行,XP SP1上能正常运行吗?
- 我在网页上放了一个JAVA按钮控制背景音乐,在我的机子上运行正常,可在别的机子却产生错误,源代码如下。。。(急,在线等待)
- 利用javaCompiler.run如何同时编译一个文件夹中的所有java文件
- java url 去掉特殊字符问题
- java中定义的字符串操作符,如何让运算时先执行括号里的
是将二进制数据转换成Java的基本类型数据。
我看,像是在网络通信或者文件存储等信息交互方面使用的代码。
每个方法都不一样,感觉,应该不会出自同一个人编写的代码。
因为,感觉,几个方法的应用场景不同。
其次,没有理解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));
}
}