首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java 依据特定数据结构 打自定义包-解包篇

2012-08-28 
java 根据特定数据结构 打自定义包------解包篇自定义的数据结构在解包的过程中用到,没有这个数据结构的话

java 根据特定数据结构 打自定义包------解包篇
自定义的数据结构在解包的过程中用到,没有这个数据结构的话,解包就无从谈起了!
好了,直接上代码!酷毙的程序员一切尽在代码中!

/** * read len   off ->len   * 读一段从偏移位置开始读 * @param fis * @param off * @param len * @return buf -> int  * @throws IOException */public static int readNext(FileInputStream fis ,int off,int len) throws IOException{off++;if(len==1){byte [] buf = new byte[off+len];fis.read(buf,off,len);int length = (int)buf[off];System.out.println( "this readNext length is :"+length);return length;}else{byte [] buf = new byte[off+len];fis.read(buf,off,len);byte [] buf2 = new byte[4];for(int i=buf.length-4;i<=buf.length;i++){buf2[3]=buf[buf.length-1];buf2[2]=buf[buf.length-2];buf2[1]=buf[buf.length-3];buf2[0]=buf[buf.length-4];}System.out.println( "this readNext ==byte 2 int== length is :"+bytesToInt(buf2));return bytesToInt(buf2);}}


基本如此。既然是打包的话当然需要压缩。文件压缩算法采取那种呢!还再思考中,写完后将继续发出来!谢谢!希望看的大神们留下思路!

热点排行