From bd6b35a93d34380ae2462d06426bdab015126ec0 Mon Sep 17 00:00:00 2001 From: scwf Date: Sat, 22 Mar 2014 12:51:57 +0800 Subject: [PATCH] fix java.nio.charset.MalformedInputException spark running on windows will throw the java.nio.charset.MalformedInputException. that's because windows use ISO8859-1 for Source.fromInputStream --- core/src/main/scala/org/apache/spark/util/Utils.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/org/apache/spark/util/Utils.scala b/core/src/main/scala/org/apache/spark/util/Utils.scala index 13d9dbdd9af2d..388681b048c7c 100644 --- a/core/src/main/scala/org/apache/spark/util/Utils.scala +++ b/core/src/main/scala/org/apache/spark/util/Utils.scala @@ -26,7 +26,7 @@ import java.util.concurrent.{ConcurrentHashMap, Executors, ThreadPoolExecutor} import scala.collection.JavaConversions._ import scala.collection.Map import scala.collection.mutable.ArrayBuffer -import scala.io.Source +import scala.io.{Codec, Source} import scala.reflect.ClassTag import com.google.common.io.Files @@ -644,6 +644,11 @@ private[spark] object Utils extends Logging { for ((key, value) <- extraEnvironment) { environment.put(key, value) } + implicit val codec = if (System.getProperty("os.name").startsWith("Windows")) { + Codec.ISO8859 + } else { + Codec.UTF8 + } val process = builder.start() new Thread("read stderr for " + command(0)) { override def run() {