You should use the ObjectStream stream wrapper on top of your data stream, many built-in types in Java are Serializable (which is an interface), which means they have built-in methods to put it self into data and then back into an object (Very convient).