Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serialize bloom filter from Google Guava?

I'm trying to use Google Guava's Bloom filter and serialize it using Scala. Creating it was easy:

import com.google.common.hash.{BloomFilter,Funnels}
val b = BloomFilter.create(Funnels.unencodedCharsFunnel,5e8.toLong,1e-6)

But I don't understand how to serialize it.. Was expecting a BloomFilter.serialize method, but no.. What am I missing?

The poit is trying to turn the Bloom filter to an Array[Byte]..

like image 365
shakedzy Avatar asked Nov 25 '25 17:11

shakedzy


1 Answers

Did you try this:

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import com.google.common.hash.{BloomFilter,Funnels} 

val b = BloomFilter.create(Funnels.unencodedCharsFunnel,5e8.toLong,1e-6)

val stream = new ObjectOutputStream(new FileOutputStream(
          "/path/to/file/file.obj"))

stream.writeObject(b)
like image 123
Samar Avatar answered Nov 27 '25 15:11

Samar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!