@@ -158,29 +158,22 @@ class << self
158158 # the graph or repository to dump
159159 # @param [IO, File, String] io
160160 # the output stream or file to write to
161- # @param [Encoding, String, Symbol] encoding
162- # the encoding to use on the output stream.
163- # Defaults to the format associated with `content_encoding`.
164161 # @param [Hash{Symbol => Object}] options
165162 # passed to {RDF::Writer#initialize} or {RDF::Writer.buffer}
166163 # @return [void]
167- def self . dump ( data , io = nil , encoding : nil , **options )
168- if io . is_a? ( String )
169- io = File . open ( io , 'w' )
170- elsif io . respond_to? ( :external_encoding ) && io . external_encoding
171- encoding ||= io . external_encoding
172- end
173- io . set_encoding ( encoding ) if io . respond_to? ( :set_encoding ) && encoding
164+ def self . dump ( data , io = nil , **options )
165+ io = File . open ( io , 'w' ) if io . is_a? ( String )
174166 method = data . respond_to? ( :each_statement ) ? :each_statement : :each
175167 if io
176- new ( io , encoding : encoding , **options ) do |writer |
168+ new ( io , **options ) do |writer |
169+ io . set_encoding ( writer . encoding ) if io . respond_to? ( :set_encoding )
177170 data . send ( method ) do |statement |
178171 writer << statement
179172 end
180173 writer . flush
181174 end
182175 else
183- buffer ( encoding : encoding , **options ) do |writer |
176+ buffer ( **options ) do |writer |
184177 data . send ( method ) do |statement |
185178 writer << statement
186179 end
@@ -191,23 +184,21 @@ def self.dump(data, io = nil, encoding: nil, **options)
191184 ##
192185 # Buffers output into a string buffer.
193186 #
194- # @param [Encoding, String, Symbol] encoding
195- # the encoding to use on the output stream.
196- # Defaults to the format associated with `content_encoding`.
197187 # @param [Hash{Symbol => Object}] options
198188 # passed to {RDF::Writer#initialize}
199189 # @yield [writer]
200190 # @yieldparam [RDF::Writer] writer
201191 # @yieldreturn [void]
202192 # @return [String]
203193 # @raise [ArgumentError] if no block is provided
204- def self . buffer ( *args , encoding : nil , **options , &block )
205- encoding ||= Encoding ::UTF_8 if RUBY_PLATFORM == "java"
194+ def self . buffer ( *args , **options , &block )
206195 raise ArgumentError , "block expected" unless block_given?
207196
208197 StringIO . open do |buffer |
209- buffer . set_encoding ( encoding ) if encoding
210- self . new ( buffer , *args , encoding : encoding , **options ) { |writer | block . call ( writer ) }
198+ self . new ( buffer , *args , **options ) do |writer |
199+ buffer . set_encoding ( writer . encoding )
200+ block . call ( writer )
201+ end
211202 buffer . string
212203 end
213204 end
@@ -216,19 +207,18 @@ def self.buffer(*args, encoding: nil, **options, &block)
216207 # Writes output to the given `filename`.
217208 #
218209 # @param [String, #to_s] filename
219- # @param [Encoding, String, Symbol] encoding
220- # the encoding to use on the output stream.
221- # Defaults to the format associated with `content_encoding`.
222210 # @param [Symbol] format (nil)
223211 # @param [Hash{Symbol => Object}] options
224212 # any additional options (see {RDF::Writer#initialize} and {RDF::Format.for})
225213 # @return [RDF::Writer]
226- def self . open ( filename , encoding : nil , format : nil , **options , &block )
214+ def self . open ( filename , format : nil , **options , &block )
227215 File . open ( filename , 'wb' ) do |file |
228- file . set_encoding ( encoding ) if encoding
229216 format_options = options . dup
230217 format_options [ :file_name ] ||= filename
231- self . for ( format || format_options ) . new ( file , encoding : encoding , **options , &block )
218+ self . for ( format || format_options ) . new ( file , **options ) do |writer |
219+ file . set_encoding ( writer . encoding )
220+ block . call ( writer )
221+ end
232222 end
233223 end
234224
0 commit comments