5353import org .jruby .util .TypeConverter ;
5454import org .jruby .util .io .EncodingUtils ;
5555import org .jruby .util .io .Getline ;
56+ import org .jruby .util .io .IOEncodable ;
5657import org .jruby .util .io .ModeFlags ;
5758import org .jruby .util .io .OpenFile ;
5859
@@ -296,14 +297,18 @@ private void strioInit(ThreadContext context, int argc, IRubyObject arg0, IRubyO
296297 break ;
297298 }
298299 Encoding encoding = null ;
300+ Object vmodeVperm = EncodingUtils .vmodeVperm (null , null );
301+ int [] oflags = {0 };
302+ int [] fmode = {0 };
299303
304+ // TODO: replace with EncodingUtils#extractModeEncoding
300305 IRubyObject options = ArgsUtil .getOptionsArg (runtime , maybeOptions );
306+ IOEncodable .ConvConfig ioEncodable = new IOEncodable .ConvConfig ();
301307 if (!options .isNil ()) {
302308 argc --;
303- IRubyObject encodingOpt = ArgsUtil .extractKeywordArg (context , "encoding" , (RubyHash ) options );
304- if (!encodingOpt .isNil ()) {
305- encoding = EncodingUtils .toEncoding (context , encodingOpt );
306- }
309+ EncodingUtils .extractModeEncoding (context , ioEncodable , vmodeVperm , options , oflags , fmode );
310+ ptr .flags = fmode [0 ];
311+ encoding = ioEncodable .enc ;
307312 }
308313
309314 switch (argc ) {
@@ -312,11 +317,11 @@ private void strioInit(ThreadContext context, int argc, IRubyObject arg0, IRubyO
312317 final boolean trunc ;
313318 if (mode instanceof RubyFixnum ) {
314319 int flags = RubyFixnum .fix2int (mode );
315- ptr .flags = ModeFlags .getOpenFileFlagsFor (flags );
320+ ptr .flags | = ModeFlags .getOpenFileFlagsFor (flags );
316321 trunc = (flags & ModeFlags .TRUNC ) != 0 ;
317322 } else {
318323 String m = arg1 .convertToString ().toString ();
319- ptr .flags = OpenFile .ioModestrFmode (runtime , m );
324+ ptr .flags | = OpenFile .ioModestrFmode (runtime , m );
320325 trunc = m .length () > 0 && m .charAt (0 ) == 'w' ;
321326 }
322327 string = arg0 .convertToString ();
@@ -329,11 +334,11 @@ private void strioInit(ThreadContext context, int argc, IRubyObject arg0, IRubyO
329334 break ;
330335 case 1 :
331336 string = arg0 .convertToString ();
332- ptr .flags = string .isFrozen () ? OpenFile .READABLE : OpenFile .READWRITE ;
337+ ptr .flags | = string .isFrozen () ? OpenFile .READABLE : OpenFile .READWRITE ;
333338 break ;
334339 case 0 :
335340 string = RubyString .newEmptyString (runtime , runtime .getDefaultExternalEncoding ());
336- ptr .flags = OpenFile .READWRITE ;
341+ ptr .flags | = OpenFile .READWRITE ;
337342 break ;
338343 default :
339344 // should not be possible
0 commit comments