Writes this BloomFilter to an output stream, with a custom format (not Java serialization). This has been measured to save at least 400 bytes compared to regular serialization. Use plain #readFrom(InputStream, Funnel) to reconstruct the written BloomFilter.
(OutputStream out)
| 483 | |
| 484 | |
| 485 | public void writeTo(OutputStream out) throws IOException { |
| 486 | // Serial form: |
| 487 | // 1 signed byte for the strategy |
| 488 | // 1 unsigned byte for the number of hash functions |
| 489 | // 1 big endian int, the number of longs in our bitset |
| 490 | // N big endian longs of our bitset |
| 491 | DataOutputStream dout = new DataOutputStream(out); |
| 492 | dout.writeByte(SignedBytes.checkedCast(strategy.ordinal())); |
| 493 | dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor |
| 494 | dout.writeInt(bits.data.length); |
| 495 | for (long value : bits.data) { |
| 496 | dout.writeLong(value); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Reads a byte stream, which was written by {@linkplain #writeTo(OutputStream)}, into a |
no test coverage detected