(PUP-1707) StringIO#set_encoding doesn't exist in ruby 1.8

Only call the method if the object responds to it.
Merge branch 'master' of https://github.com/puppetlabs/puppet