If you're using files to pass data around between different components of a system it may make sense to use Thrift. Doing so means you get smaller file sizes (assuming you do binary serialization) but still have files that can be easily read in many programming languages.
In Java, writing Thrift objects to disk is straightforward. Here's a utility class that I use for doing so:
If you have a Thrift object called Album and you'd like to write a list of them to file you'd do it like so:
ThriftWriter uses the interface com.facebook.thrift.TBase, which defines the methods needed for reading and writing a Thrift object to a Thrift protocol. We could use a single ThriftWriter to write any number of different objects to disk, since they all implement TBase, but then you'd have to make sure you knew what order the objects came in when reading the file.
comments powered by Disqus