本文整理汇总了Java中net.jpountz.xxhash.StreamingXXHash32类的典型用法代码示例。如果您正苦于以下问题:Java StreamingXXHash32类的具体用法?Java StreamingXXHash32怎么用?Java StreamingXXHash32使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StreamingXXHash32类属于net.jpountz.xxhash包,在下文中一共展示了StreamingXXHash32类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: hashOfFile
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的package包/类
public static int hashOfFile(
final Path file,
final int salt) throws IOException {
Preconditions.checkNotNull(file, "file is null");
StreamingXXHash32 hash32 = FACTORY.newStreamingHash32(salt);
ByteBuffer buf = ByteBuffer.allocate(8192);
byte[] b = new byte[8192];
try (FileInputStream in = new FileInputStream(file.toFile())) {
FileChannel channel = in.getChannel();
long len;
while ((len = channel.read(buf)) != -1) {
buf.flip();
buf.get(b, 0, (int) len);
hash32.update(b, 0, (int) len);
buf.clear();
}
}
return hash32.getValue();
}
开发者ID:clidev,项目名称:spike.x,代码行数:23,代码来源:XXHash32.java
示例2: fastHashing
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的package包/类
private Integer fastHashing(String strData) throws IOException{
byte[] data = strData.getBytes();
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 = factory.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);
}
Integer hash = hash32.getValue();
return hash;
}
开发者ID:EIS-Bonn,项目名称:Luzzu,代码行数:22,代码来源:GraphSigning.java
示例3: compressBlock
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的package包/类
private static ByteBuf compressBlock(LZ4Compressor compressor, StreamingXXHash32 checksum, byte[] bytes, int off, int len) {
assert len != 0;
int compressionLevel = compressionLevel(len < MIN_BLOCK_SIZE ? MIN_BLOCK_SIZE : len);
int outputBufMaxSize = HEADER_LENGTH + ((compressor == null) ? len : compressor.maxCompressedLength(len));
ByteBuf outputBuf = ByteBufPool.allocate(outputBufMaxSize);
outputBuf.put(MAGIC);
byte[] outputBytes = outputBuf.array();
checksum.reset();
checksum.update(bytes, off, len);
int check = checksum.getValue();
int compressedLength = len;
if (compressor != null) {
compressedLength = compressor.compress(bytes, off, len, outputBytes, HEADER_LENGTH);
}
int compressMethod;
if (compressor == null || compressedLength >= len) {
compressMethod = COMPRESSION_METHOD_RAW;
compressedLength = len;
System.arraycopy(bytes, off, outputBytes, HEADER_LENGTH, len);
} else {
compressMethod = COMPRESSION_METHOD_LZ4;
}
outputBytes[MAGIC_LENGTH] = (byte) (compressMethod | compressionLevel);
writeIntLE(compressedLength, outputBytes, MAGIC_LENGTH + 1);
writeIntLE(len, outputBytes, MAGIC_LENGTH + 5);
writeIntLE(check, outputBytes, MAGIC_LENGTH + 9);
assert MAGIC_LENGTH + 13 == HEADER_LENGTH;
outputBuf.writePosition(HEADER_LENGTH + compressedLength);
return outputBuf;
}
开发者ID:softindex,项目名称:datakernel,代码行数:40,代码来源:StreamLZ4Compressor.java
示例4: readBody
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的package包/类
private static ByteBuf readBody(LZ4FastDecompressor decompressor, StreamingXXHash32 checksum, Header header,
byte[] bytes, int off) throws ParseException {
ByteBuf outputBuf = ByteBufPool.allocate(header.originalLen);
outputBuf.writePosition(header.originalLen);
switch (header.compressionMethod) {
case COMPRESSION_METHOD_RAW:
System.arraycopy(bytes, off, outputBuf.array(), 0, header.originalLen);
break;
case COMPRESSION_METHOD_LZ4:
try {
int compressedLen2 = decompressor.decompress(bytes, off, outputBuf.array(), 0, header.originalLen);
if (header.compressedLen != compressedLen2) {
throw new ParseException("Stream is corrupted");
}
} catch (LZ4Exception e) {
throw new ParseException("Stream is corrupted", e);
}
break;
default:
throw new AssertionError();
}
checksum.reset();
checksum.update(outputBuf.array(), 0, header.originalLen);
if (checksum.getValue() != header.check) {
throw new ParseException("Stream is corrupted");
}
return outputBuf;
}
开发者ID:softindex,项目名称:datakernel,代码行数:29,代码来源:StreamLZ4Decompressor.java
示例5: getHash
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的package包/类
public int getHash(final SimpleFeature feature) {
this.startMeasuring();
try {
final int seed = 0x12af028e;
StreamingXXHash32 hash32 = this.hashFactory.newStreamingHash32(seed);
if (this.includeGeometry) {
final Geometry geom = (Geometry) feature.getDefaultGeometry();
if (geom != null) {
final byte[] geomBytes = wkbWriter.write(geom);
hash32.update(geomBytes, 0, geomBytes.length);
}
}
final Iterator<String> attributeIt = this.includedAttributes.iterator();
while (attributeIt.hasNext()) {
final String attributeName = attributeIt.next();
final Object value = feature.getAttribute(attributeName);
if (value != null) {
final byte[] valueBytes = value.toString().getBytes();
hash32.update(valueBytes, 0, valueBytes.length);
}
}
return hash32.getValue();
} finally {
this.stopMeasuring();
}
}
开发者ID:geops,项目名称:trafimage-geoserver-transformations,代码行数:29,代码来源:SimpleFeatureHasher.java
示例6: StreamLZ4Decompressor
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的package包/类
private StreamLZ4Decompressor(LZ4FastDecompressor decompressor, StreamingXXHash32 checksum) {
this.decompressor = decompressor;
this.checksum = checksum;
recreate();
}
开发者ID:softindex,项目名称:datakernel,代码行数:6,代码来源:StreamLZ4Decompressor.java
示例7: create
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的package包/类
public static StreamLZ4Decompressor create(LZ4FastDecompressor decompressor,
StreamingXXHash32 checksum) {
return new StreamLZ4Decompressor(decompressor, checksum);
}
开发者ID:softindex,项目名称:datakernel,代码行数:5,代码来源:StreamLZ4Decompressor.java
示例8: Output
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的package包/类
private Output(LZ4FastDecompressor decompressor, StreamingXXHash32 checksum) {
this.decompressor = decompressor;
this.checksum = checksum;
}
开发者ID:softindex,项目名称:datakernel,代码行数:5,代码来源:StreamLZ4Decompressor.java
示例9: main
import net.jpountz.xxhash.StreamingXXHash32; //导入依赖的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
注:本文中的net.jpountz.xxhash.StreamingXXHash32类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论