@@ -320,27 +320,17 @@ public static SixModelObject setencoding(SixModelObject obj, String encoding, Th
320
320
321
321
String charset = null ;
322
322
if (encoding .equals ("ascii" ))
323
- charset = "US-ASCII" ;
323
+ h . encoding = "US-ASCII" ;
324
324
else if (encoding .equals ("iso-8859-1" ))
325
- charset = "ISO-8859-1" ;
325
+ h . encoding = "ISO-8859-1" ;
326
326
else if (encoding .equals ("utf8" ))
327
- charset = "UTF-8" ;
327
+ h . encoding = "UTF-8" ;
328
328
else if (encoding .equals ("utf16" ))
329
- charset = "UTF-16" ;
329
+ h . encoding = "UTF-16" ;
330
330
else if (encoding .equals ("binary" ))
331
- charset = "ISO-8859-1" ; /* Byte oriented... */
331
+ h . encoding = "ISO-8859-1" ; /* Byte oriented... */
332
332
else
333
333
die_s ("Unsupported encoding " + encoding , tc );
334
-
335
- try {
336
- if (h .is != null )
337
- h .isr = new InputStreamReader (h .is , charset );
338
- if (h .os != null )
339
- h .osw = new OutputStreamWriter (h .os , charset );
340
- }
341
- catch (UnsupportedEncodingException e ) {
342
- die_s (e .getMessage (), tc );
343
- }
344
334
}
345
335
else {
346
336
die_s ("setencoding requires an object with the IOHandle REPR" , tc );
@@ -366,7 +356,7 @@ public static String printfh(SixModelObject obj, String data, ThreadContext tc)
366
356
die_s ("File handle is not opened for write" , tc );
367
357
try {
368
358
if (h .osw == null )
369
- h .osw = new OutputStreamWriter (h .os , "UTF-8" );
359
+ h .osw = new OutputStreamWriter (h .os , h . encoding );
370
360
h .osw .write (data );
371
361
h .osw .flush ();
372
362
}
@@ -393,7 +383,7 @@ public static String readlinefh(SixModelObject obj, ThreadContext tc) {
393
383
die_s ("File handle is not opened for read" , tc );
394
384
try {
395
385
if (h .isr == null )
396
- h .isr = new InputStreamReader (h .is , "UTF-8" );
386
+ h .isr = new InputStreamReader (h .is , h . encoding );
397
387
if (h .br == null )
398
388
h .br = new BufferedReader (h .isr );
399
389
String line = h .br .readLine ();
@@ -448,7 +438,7 @@ public static String readallfh(SixModelObject obj, ThreadContext tc) {
448
438
die_s ("File handle is not opened for read" , tc );
449
439
try {
450
440
if (h .isr == null )
451
- h .isr = new InputStreamReader (h .is , "UTF-8" );
441
+ h .isr = new InputStreamReader (h .is , h . encoding );
452
442
if (h .br == null )
453
443
h .br = new BufferedReader (h .isr );
454
444
0 commit comments