CoverityFix CID:1350859 Dubious method used 05/20405/3
Nimish Kapoor [Tue, 31 Jul 2018 19:14:56 +0000 (00:14 +0530)]
Found a call to a method which will perform a byte to String (or String to byte)
conversion, and will assume that the default platform encoding is suitable. This
will cause the application behaviour to vary between platforms. Use an
alternative API and specify a charset name or Charset object explicitly.
https://stackoverflow.com/questions/696626/java-filereader-encoding-issue

Change-Id: I228ff4c4ed6756c1a7a47f4f6659141aa7ffcc7a

scilab/modules/helptools/src/java/org/scilab/modules/helptools/source/ScilabSourceBrowser.java

index e08675b..8a320b4 100644 (file)
@@ -24,6 +24,8 @@ import java.io.Reader;
 import java.io.Writer;
 import java.io.InputStreamReader;
 import java.io.FileInputStream;
+import java.io.OutputStreamWriter;
+import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -65,7 +67,7 @@ public class ScilabSourceBrowser extends HTMLScilabCodeHandler {
                 System.out.println(f);
                 Reader input = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
                 currentCommand = f.getName().split("\\.")[0];
-                buffer = new FileWriter(outputDirectory + File.separator + currentCommand + ".html");
+                buffer = new OutputStreamWriter(new FileOutputStream(outputDirectory + File.separator + currentCommand + ".html"), "UTF-8");
                 buffer.append(entete);
                 buffer.append("<div style=\"code\"><pre>");
                 scilabLexer.convert(this, input, false);