[server][testMain] Move a class for opening file with a some clean up so that other functioins can use it.