当前位置: 首页>>代码示例>>Java>>正文


Java XXHashFactory.newStreamingHash32方法代码示例

本文整理汇总了Java中net.jpountz.xxhash.XXHashFactory.newStreamingHash32方法的典型用法代码示例。如果您正苦于以下问题:Java XXHashFactory.newStreamingHash32方法的具体用法?Java XXHashFactory.newStreamingHash32怎么用?Java XXHashFactory.newStreamingHash32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.jpountz.xxhash.XXHashFactory的用法示例。


在下文中一共展示了XXHashFactory.newStreamingHash32方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import net.jpountz.xxhash.XXHashFactory; //导入方法依赖的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);
    }
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:53,代码来源:TestLz4.java

示例2: FastHash

import net.jpountz.xxhash.XXHashFactory; //导入方法依赖的package包/类
public FastHash() {
	XXHashFactory factory = XXHashFactory.fastestInstance();
	int seed = 0x9747b28f; 
	hash32 = factory.newStreamingHash32(seed);
}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:6,代码来源:FastHash.java


注:本文中的net.jpountz.xxhash.XXHashFactory.newStreamingHash32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。