Code example for ObjectOutputStream

Methods: flush, writeObject

0
{ 
    public void serialize(LegacyBloomFilter bf, DataOutputStream dos)
            throws IOException 
    { 
        dos.writeInt(bf.getHashCount());
        ObjectOutputStream oos = new ObjectOutputStream(dos);
        oos.writeObject(bf.getBitSet());
        oos.flush();
    } 
 
    public LegacyBloomFilter deserialize(DataInputStream dis) throws IOException
    { 
        int hashes = dis.readInt();
        ObjectInputStream ois = new ObjectInputStream(dis);
        try 
        { 
          BitSet bs = (BitSet) ois.readObject();
          return new LegacyBloomFilter(hashes, bs);
        } catch (ClassNotFoundException e)
        { 
          throw new RuntimeException(e);