I get a line of overhead ("java.util.BitSet"
) when writing a BitSet to an output file using ObjectOutputStream.writeObject()
.
Anyway around it?
That is not an "overhead", that't the marker that lets Java figure out what type it needs to create when deserializing the object from that file.
Since ObjectInputStream
has no idea what you have serialized into a file, and has no way for you to provide a "hint", ObjectOutputStream
must "embed" something for the input stream to be able to decide what class needs to be instantiated. That is why it places the "java.util.BitSet"
string in front of the data of your BitSet
.
You cannot get around writing this marker when you use serialization capabilities built into BitSet
class. If you are serializing the object into a file by itself, with no other objects going in with it, you could write the result of toByteArray()
call into a file, and call BitSet.valueOf(byteArray)
after reading byteArray
from the file.