add write logic to java example