首页 > 代码库 > java_zlib_资料
java_zlib_资料
1、网页资料
1.1、http://bbs.csdn.net/topics/190020986
1.2、
http://cdn.verydemo.com/demo_c89_i166794.html
http://blog.csdn.net/hexingyeyun/article/details/8678154
1.3、
http://www.lai18.com/content/2088054.html
http://www.jb51.net/article/95073.htm
1.4、Delphi external 使用 ?.obj中的函数:http://bbs.csdn.net/topics/60347700
2、我的测试代码
2.1、
procedure TForm1.Button2Click(Sender: TObject); var cs :TCompressionStream; ms :TMemoryStream; pc :PChar; buffer :PCHar; i :integer; begin pc := ‘Test123456‘; ms := TMemoryStream.Create; cs := TCompressionStream.Create(clMax, ms); // (clNone, clFastest, clDefault, clMax); cs.Write(pc[0], strlen(pc)); cs.Free; Memo1.Lines.Add(‘-->‘+inttostr(ms.size)); GetMem(buffer, ms.size); ms.Read(buffer[0], ms.size); for i:=0 to ms.size do Memo1.Lines.Add(inttostr(integer(buffer[i]))); end; procedure TForm1.Button3Click(Sender: TObject); var zip: TVclZip; compr: string; data: PChar; txt :PChar; arr :array[0..256] of byte; iOut :integer; p :pointer; i :integer; begin txt := ‘Test123456‘; iOut := 0; zip := TVclZip.Create(nil); for i:=0 to 17 do Memo1.Lines.Add(inttostr(integer(arr[i]))); p := nil; zip.ZLibCompressBuffer(txt, strlen(txt), p, iOut); zip.Free; Memo1.Lines.Add(‘-->‘+inttostr(iOut)); for i:=0 to iOut-1 do Memo1.Lines.Add(inttostr(integer(PChar(p)[i]))); end;
2.2、
package str; import java.io.ByteArrayOutputStream; import java.sql.ResultSet; import java.util.zip.DeflaterOutputStream; import java.util.zip.GZIPOutputStream; import java.util.zip.InflaterOutputStream; public class TstrTest { public static void main(String[] args) throws Exception { // String str = "退出"; // // byte[] bytesGBK = str.getBytes("gbk"); // for (int i=0; i<bytesGBK.length; i++) // System.out.print(String.format("%02X ", bytesGBK[i])); // System.out.println(); // // byte[] bytesUTF8 = str.getBytes("utf-8"); // for (int i=0; i<bytesUTF8.length; i++) // System.out.print(String.format("%02X ", bytesUTF8[i])); ByteArrayOutputStream bao = new ByteArrayOutputStream(); //InflaterOutputStream ios = new InflaterOutputStream(bao); DeflaterOutputStream dos = new DeflaterOutputStream(bao); String str = "Test123456"; dos.write(str.getBytes("iso-8859-1")); dos.close(); byte[] bytes = bao.toByteArray(); for (int i=0; i<bytes.length; i++) System.out.println(i+" : " + ((int)bytes[i] & 0xFF)); //SevenZArchiveEntry ss; System.out.println(); bytes = Compress(str.getBytes("iso-8859-1")); for (int i=0; i<bytes.length; i++) System.out.println(i+" : " + ((int)bytes[i] & 0xFF)); } public static byte[] Compress(byte[] _bytes) throws Exception { if (_bytes == null || _bytes.length == 0) return null; ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(out); gzip.write(_bytes); gzip.close(); return out.toByteArray(); } }
ZC: 仔细对比 java代码中 zlib和gzip 压缩出来的数据 其实是一样的,只是 头部&尾部不同而已,也印证了上面 网页资料1.3 中的说法
3、
java_zlib_资料
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。