java gzip delphi_Delphi中获取IE网页后,对GZIP方式的网页解压(gzip,deflate)

使用 ICS控件,我现在对这套控件简直都要爱不释手了

Code:

var

_DecompresData :string;

czlib : THttpCCodzlib;

procedure TMyClass.OnDecompresData(Buffer: Pointer; Count: Integer);

var

iLen: integer;

begin

iLen := length(_DecompresData);

SetLength(_DecompresData, iLen + Count);

CopyMemory(@_DecompresData[iLen + 1], Buffer, Count);

end;

使用:

if ContentEncoding = 'gzip' then

begin

_DecompresData := '';

czlib := THttpCCodzlib.Create(OnDecompresData);

Result := FHttpData.DataString;

czlib.WriteBuffer(@Result[1], Length(Result));

czlib.Complete;

Result := _DecompresData;

czlib.Free;

end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Java,我们可以使用deflate算法对字符串进行解压缩。deflate是一种常用的数据压缩算法,可以将数据进行压缩以节省空间。要对字符串进行deflate解压,首先需要使用java.util.zip.Inflater类来创建一个解压缩器。然后将需要解压的字符串转换成字节数组,使用解压缩器的方法解压缩字节数组,最后将解压缩后的字节数组转换成字符串即可得到解压缩后的结果。 下面是一个简单的示例代码,演示了如何在Java使用deflate解压字符串: ```java import java.io.ByteArrayOutputStream; import java.util.zip.DataFormatException; import java.util.zip.Inflater; public class DeflateDecompress { public static String decompress(String compressedString) throws DataFormatException { byte[] compressedData = compressedString.getBytes(); Inflater inflater = new Inflater(); inflater.setInput(compressedData); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(compressedData.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { try { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } catch (DataFormatException e) { e.printStackTrace(); } } try { outputStream.close(); } catch (Exception ex) { ex.printStackTrace(); } byte[] decompressedData = outputStream.toByteArray(); return new String(decompressedData); } public static void main(String[] args) { try { String compressedString = "这里是压缩后的字符串"; String decompressedString = decompress(compressedString); System.out.println("解压缩后的结果:" + decompressedString); } catch (DataFormatException e) { e.printStackTrace(); } } } ``` 通过上面的示例代码,我们可以在Java使用deflate算法对字符串进行解压缩,并且得到解压缩后的结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

罗延辉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值