I don't know if this is appropriate. But I kept getting Malformed Input
exceptions when trying to read a model file with:
./sbt "run-main org.nlogo.headless.Main --model model.nlogo --experiment
experiment
[error] (run-main-0) java.nio.charset.MalformedInputException: Input length = 1
java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.read1(BufferedReader.java:210)
at java.io.BufferedReader.read(BufferedReader.java:286)
at java.io.Reader.read(Reader.java:140)
at scala.io.BufferedSource.mkString(BufferedSource.scala:96)
at org.nlogo.api.FileIO$.file2String(FileIO.scala:11)
After poking around awhile, I found this hack:
http://stackoverflow.com/questions/13625024/how-to-read-a-text-file-with-mixed-encodings-in-scala-or-java
So I changed src/main/api/FileIO.scala like so:
------------------------------------------------
diff --git a/src/main/api/FileIO.scala b/src/main/api/FileIO.scala
index c559ac3..b002088 100644
--- a/src/main/api/FileIO.scala
+++ b/src/main/api/FileIO.scala
@@ -2,13 +2,21 @@
package org.nlogo.api
+import scala.io.Codec
+import java.nio.charset.CodingErrorAction
+
import org.nlogo.core.FileMode
object FileIO {
@throws(classOf[java.io.IOException])
- def file2String(path: String) =
+ def file2String(path: String) = {
+ implicit val codec = scala.io.Codec("UTF-8")
+ codec.onMalformedInput(CodingErrorAction.REPLACE)
+ codec.onUnmappableCharacter(CodingErrorAction.REPLACE)
+
io.Source.fromFile(path).mkString
+ }
@throws(classOf[java.io.IOException])
def writeFile(path: String, text: String) {
-------------------------------------------------
And now it works ... Just FYI. I'm not claiming it's proper... but it worked.
;-)
--
glen ep ropella -- 971-255-2847
--
glen ep ropella -- 971-255-2847
--
You received this message because you are subscribed to the Google Groups
"netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.