There's no method called write in DataOutputStream that writes out the type Key. Unfortunately, Java doesn't let you use pointers so you can't pass the byte values one-by-one through the output...