Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lizhirui opened this issue Mar 31, 2021 · 5 comments
Open

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

lizhirui opened this issue Mar 31, 2021 · 5 comments

Comments

@lizhirui
Copy link
Contributor

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)

@yzt000000
Copy link

yzt000000 commented Jul 25, 2021

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

@vr2045
Copy link

vr2045 commented Mar 14, 2022

I see the same issue...

@trey-king
Copy link

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

@ranshuo-ICer
Copy link

ranshuo-ICer commented Mar 10, 2023

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

@thepalbi
Copy link

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

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants