import net.jpountz.lz4.LZ4SafeDecompressor; //导入方法依赖的package包/类

public static void main(String[] args) throws IOException {

LZ4Factory factory = LZ4Factory.fastestInstance();

byte[] data = "Compressors and decompressors are interchangeable: it is perfectly correct to compress with the JNI bindings and to decompress with a Java port, or the other way around.Compressors might not generate the same compressed streams on all platforms, especially if CPU endianness differs, but the compressed streams can be safely decompressed by any decompressor implementation on any platform.Compressors and decompressors are interchangeable: it is perfectly correct to compress with the JNI bindings and to decompress with a Java port, or the other way around.Compressors might not generate the same compressed streams on all platforms, especially if CPU endianness differs, but the compressed streams can be safely decompressed by any decompressor implementation on any platform.".getBytes("UTF-8");

final int decompressedLength = data.length;

System.out.println("dataLength:" + decompressedLength);

// compress data

LZ4Compressor compressor = factory.fastCompressor();

int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);

byte[] compressed = new byte[maxCompressedLength];

int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength);

System.out.println("compressedLength:" + compressedLength);

// decompress data

// - method 1: when the decompressed length is known

LZ4FastDecompressor decompressor = factory.fastDecompressor();

byte[] restored = new byte[decompressedLength];

int compressedLength2 = decompressor.decompress(compressed, 0, restored, 0, decompressedLength);

// compressedLength == compressedLength2

System.out.println("compressedLength2:" + compressedLength2);

// - method 2: when the compressed length is known (a little slower)

// the destination buffer needs to be over-sized

LZ4SafeDecompressor decompressor2 = factory.safeDecompressor();

int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0);

// decompressedLength == decompressedLength2

System.out.println("decompressedLength2:" + compressedLength);

XXHashFactory factory1 = XXHashFactory.fastestInstance();

ByteArrayInputStream in = new ByteArrayInputStream(data);

int seed = 0x9747b28c; // used to initialize the hash value, use whatever

// value you want, but always the same

StreamingXXHash32 hash32 = factory1.newStreamingHash32(seed);

byte[] buf = new byte[8]; // for real-world usage, use a larger buffer, like 8192 bytes

for (;;) {

int read = in.read(buf);

if (read == -1) {

break;

}

hash32.update(buf, 0, read);

}

int hash = hash32.getValue();

System.out.println(hash);

}

java的方法decompress_Java LZ4SafeDecompressor.decompress方法代码示例相关推荐

  1. java事件绑定,Java编程GUI中的事件绑定代码示例

    程序绑定的概念: 绑定指的是一个方法的调用与方法所在的类(方法主体)关联起来.对java来说,绑定分为静态绑定和动态绑定:或者叫做前期绑定和后期绑定 静态绑定: 在程序执行前方法已经被绑定,此时由编译 ...

  2. java 凌晨,java获取整点与凌晨的时间戳代码示例

    本篇文章小编给大家分享一下java获取整点与凌晨的时间戳代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. Java中获取整点时间戳 在实际的开发 ...

  3. mockjs——mockjs定义、mockjs安装、mockjs使用、mockjs方法、mockjs语法、代码示例

    目录 一.mockjs定义 二.mockjs安装 三 .mockjs使用 四.mockjs方法 五.mockjs语法 六.代码示例 一.mockjs定义 拦截ajax请求,生成伪数据 应用场景:在工作 ...

  4. php simpledateformat,Java中SimpleDateFormat的用法介绍(代码示例)

    本篇文章给大家带来的内容是关于Java中SimpleDateFormat的用法介绍(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 1.为什么要使用SimpleDateFo ...

  5. java五子棋棋盘_java绘制五子棋棋盘代码示例

    本篇文章小编给大家分享一下java绘制五子棋棋盘代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. 代码如下: import javax.imag ...

  6. java map sortedmap_Java SortedMap put()用法及代码示例

    Java中SortedMap接口的put()方法用于将指定值与该映射中的指定键相关联. 用法: V put(K key, V value) 参数:此方法有两个参数: key:这是左参数, value: ...

  7. java foreach delete_Java CopyOnWriteArrayList forEach()用法及代码示例

    CopyOnWriteArrayList的forEach()方法为Iterable的每个元素执行给定的操作,直到已处理完所有元素或该操作引发异常. 用法: public void forEach (C ...

  8. java创建datetime_Java OffsetDateTime ofInstant()用法及代码示例

    Java中OffsetDateTime类的ofInstant(Instant Instant,ZoneId zone)方法用于根据指定的Instant和ZoneID创建OffsetDateTime的实 ...

  9. Java 中removelinked_Java LinkedHashSet remove()用法及代码示例

    Java.util.LinkedHashSet.remove(Object O)方法用于从LinkedHashSet中删除特定元素. 用法: LinkedHashSet.remove(Object O ...

最新文章

  1. UIPickerView 修改必须滚动才修改值的bug
  2. cve-2018-1273 Spring Expression Language 漏洞分析
  3. Python学习之猜数字小游戏
  4. andorid 自定义seekbar
  5. 全排列(递归与非递归实现)
  6. PHP开发中保证接口安全
  7. mac怎么配置php开发环境变量,Mac M1安装mnmp(Mac+Nginx+MySQL+PHP)开发环境
  8. mysql5.7参数简单介绍
  9. cartographer坐标系_cartographer个人对框架解读
  10. 贝叶斯估计和极大似然估计
  11. 关于区块链通证模型,你想知道的都在这
  12. extjs 兼容性问题解决方案
  13. 如何生成SSH key
  14. 使用ArcGIS软件进行投影变换和坐标校正
  15. 2022年安全员-A证考题模拟考试平台操作
  16. VSCode配置git图文
  17. cannot load facet kotlin
  18. 半色调技术简介(一)
  19. 将物理机迁移到ESXI上
  20. 有哪位仁兄可以告诉我,下载软件包的时候出现这种情况是怎么一回事呢?kali虚拟机,希望看见的前辈不吝赐教

热门文章

  1. 求n以内的最大素数 ← C++
  2. windows 网络远程连接samba,并修改windows默认连接samba端口445到指定端口(支持监听ipv6 及ipv4 IP地址)
  3. 服务器与Linux初体验
  4. 如何在webots中绘制运动轨迹
  5. vue2 qrcodejs2链接生成二维码
  6. 一般总账科目 调整 为统驭科目时报错:只以本位币计的统驭科目余额未定义
  7. 2021年江西省上饶市高考成绩查询,2021年上饶高考状元名单公布,上饶文理科状元是谁多少分...
  8. xstart连接linux桌面使用的端口,配置XManager5连接Linux图形化界面详解
  9. IT大学生成长周报 | 第 5 期
  10. 前端HTML5+CSS3学习笔记