chisel-bootcamp icon indicating copy to clipboard operation
chisel-bootcamp copied to clipboard

java.nio.charset.MalformedInputException: Input length = 1

Open lizhirui opened this issue 3 years ago • 5 comments

when i run code "visualize(() => new MovingAverage3(8))" in "0_demo.ipynb",i got a error that "dot" isn't exist. And then i installed graphviz 2.47.0 win64 for win10.I run this command again,and got a error "java.nio.charset.MalformedInputException: Input length = 1"

detail logs: java.nio.charset.MalformedInputException: Input length = 1 java.nio.charset.CoderResult.throwException(CoderResult.java:281) sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339) sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) java.io.InputStreamReader.read(InputStreamReader.java:184) java.io.BufferedReader.read1(BufferedReader.java:210) java.io.BufferedReader.read(BufferedReader.java:286) java.io.Reader.read(Reader.java:140) scala.io.BufferedSource.mkString(BufferedSource.scala:98) firrtl.FileUtils$.getText(FileUtils.scala:130) firrtl.FileUtils$.getText(FileUtils.scala:121) ammonite.$file.dummy.source.load$minusivy_2$Helper.generateVisualizations(Main.sc:149) ammonite.$file.dummy.source.load$minusivy_2$Helper.visualize(Main.sc:159) ammonite.$sess.cmd3$Helper.(cmd3.sc:1) ammonite.$sess.cmd3$.(cmd3.sc:7) ammonite.$sess.cmd3$.(cmd3.sc:-1)

lizhirui avatar Mar 31 '21 02:03 lizhirui

same phenomenon this line : val svgModuleText = FileUtils.getText(moduleView)

yzt000000 avatar Jul 25 '21 12:07 yzt000000

I see the same issue...

vr2045 avatar Mar 14 '22 04:03 vr2045

I see this issue as well. This is when running the demo in chisel-bootcamp.

trey-king avatar Sep 11 '22 22:09 trey-king

Hi! I have solved the issue. The issue is caused by the encoding format. In Windows, the default encoding setting is GBK (for Chinese users). So the JVM would read files in GBK format. The codes that caused the issue come from chisel-bootcamp-master\source\load-ivy.sc and are:

val svgModuleText = FileUtils.getText(moduleView)
val svgInstanceText = FileUtils.getText(instanceView)

moduleView and instanceView are two .svg files and their encoding format is UTF-8, which causes an error when JVM loads these files.

To solve the problem, we need to specify the encoding of JVM by setting the system environment variable %JAVA_TOOL_OPTIONS% to -Dfile.encoding=UTF-8. After that, reboot your system.

You can examine your JVM encoding with this codes

import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
 
class Test {
	public static void main(String[] args) {
        System.out.println("Default Charset=" + Charset.defaultCharset());
        System.out.println("file.encoding=" + System.getProperty("file.encoding"));
        System.out.println("Default Charset=" + Charset.defaultCharset());
        System.out.println("Default Charset in Use=" + getDefaultCharSet());
    }
 
    private static String getDefaultCharSet() {
        OutputStreamWriter writer = new OutputStreamWriter(new ByteArrayOutputStream());
        String enc = writer.getEncoding();
        return enc;
    }
 
}

Here are my outputs: image

ranshuo-ICer avatar Mar 10 '23 05:03 ranshuo-ICer

Confirm it works after doing what @ranshuo-ICer suggested:

image

thepalbi avatar Dec 15 '23 18:12 thepalbi