Also, please move outside the set of write() methods.  This is more "utility".  And on that note, I don't see anything stateful here, so this could be a static utility, moved further down the class.