TODO: how to flush in java