Research apache commons for this functionality also.