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)
| 486 | |
| 487 | |
| 488 | public void writeTo(OutputStream out) throws IOException { |
| 489 | // Serial form: |
| 490 | // 1 signed byte for the strategy |
| 491 | // 1 unsigned byte for the number of hash functions |
| 492 | // 1 big endian int, the number of longs in our bitset |
| 493 | // N big endian longs of our bitset |
| 494 | DataOutputStream dout = new DataOutputStream(out); |
| 495 | dout.writeByte(SignedBytes.checkedCast(strategy.ordinal())); |
| 496 | dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor |
| 497 | dout.writeInt(bits.data.length); |
| 498 | for (long value : bits.data) { |
| 499 | dout.writeLong(value); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * Reads a byte stream, which was written by {@linkplain #writeTo(OutputStream)}, into a |
no test coverage detected