这里需要注意的是,Java中int类型4个字节大小,但是由于是有符号的整数,补码的最高位是符号位,所以对于Header中的4个字节的无符号整数,必须要用long类型才足够。2个字节的无符号整数需要使用Java中的int而不能是short。
另外,Header中用到了W3GException异常。
W3GException.java
package com.xxg.w3gparser;
public class W3GException extends Exception {
public W3GException(String message) {
super(message);
}
}
最后用main方法调用这些代码来测试。
Test.java
package com.xxg.w3gparser;
import java.io.File;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException, W3GException {
Replay replay = new Replay(new File("E:/魔兽争霸3冰封王座/REPLAY/100729_[NE]EHOME.ReMinD_VS_[ORC]WemadeFOX_Lyn_EchoIsles_RN.w3g"));
Header header = replay.getHeader();
System.out.println("WAR3录像基本信息为:");
System.out.println("版本:1." + header.getVersionNumber() + "." + header.getBuildNumber());
long duration = header.getDuration();
long second = (duration / 1000) % 60;
long minite = (duration / 1000) / 60;
if (second < 10) {
System.out.println("时长:" + minite + ":0" + second);
} else {
System.out.println("时长:" + minite + ":" + second);
}
}
}
输出结果:
1-28字节:Warcraft III recorded game
29-32字节:68
33-36字节:125736
37-40字节:1
41-44字节:311296
45-48字节:38
49-52字节:W3XP
53-56字节:24
57-58字节:6059
59-60字节:32768
61-64字节:783600
65-68字节:1414752232
计算CRC32:1414752232
WAR3录像基本信息为:
版本:1.24.6059
时长:13:03
参考文档:http://w3g.deepnode.de/files/w3g_format.txt
作者:叉叉哥 转载请注明出处:http://blog.csdn.net/xiao__gui/article/details/17882303