1require 'rexml/encoding' 2 3module REXML 4 class Output 5 include Encoding 6 7 attr_reader :encoding 8 9 def initialize real_IO, encd="iso-8859-1" 10 @output = real_IO 11 self.encoding = encd 12 13 @to_utf = encoding != 'UTF-8' 14 15 if encoding == "UTF-16" 16 @output << "\ufeff".encode("UTF-16BE") 17 self.encoding = "UTF-16BE" 18 end 19 end 20 21 def <<( content ) 22 @output << (@to_utf ? self.encode(content) : content) 23 end 24 25 def to_s 26 "Output[#{encoding}]" 27 end 28 end 29end 30