Repository: zeppelin
Updated Branches:
  refs/heads/master 5ac3faeba -> e2d0ca344


[ZEPPELIN-1301] fix potential encoding problem in RInterpreter processHTML 
DataURI conversion

### What is this PR for?
fix potential encoding problem in RInterpreter processHTML DataURI conversion.
Read binary content from local file and turn into Base64 format directly.

### What type of PR is it?
Bug Fix

### Todos
N/A

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1301

### How should this be tested?
Existing tests.

### Screenshots (if appropriate)
N/A

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: WeichenXu <[email protected]>

Closes #1295 from WeichenXu123/fix_rinterpreter_script_to_base and squashes the 
following commits:

1da9382 [WeichenXu] improve code style
782cf4e [WeichenXu] fix rinterpreter script_to_base


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/e2d0ca34
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/e2d0ca34
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/e2d0ca34

Branch: refs/heads/master
Commit: e2d0ca3448d29b94e99089cfd90ac93119eb7063
Parents: 5ac3fae
Author: WeichenXu <[email protected]>
Authored: Fri Aug 5 21:32:37 2016 -0700
Committer: Lee moon soo <[email protected]>
Committed: Thu Aug 25 09:31:41 2016 -0700

----------------------------------------------------------------------
 .../org/apache/zeppelin/rinterpreter/RInterpreter.scala | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/e2d0ca34/r/src/main/scala/org/apache/zeppelin/rinterpreter/RInterpreter.scala
----------------------------------------------------------------------
diff --git 
a/r/src/main/scala/org/apache/zeppelin/rinterpreter/RInterpreter.scala 
b/r/src/main/scala/org/apache/zeppelin/rinterpreter/RInterpreter.scala
index a8e695e..f0558a9 100644
--- a/r/src/main/scala/org/apache/zeppelin/rinterpreter/RInterpreter.scala
+++ b/r/src/main/scala/org/apache/zeppelin/rinterpreter/RInterpreter.scala
@@ -17,6 +17,7 @@
 
 package org.apache.zeppelin.rinterpreter
 
+import java.io.{BufferedInputStream, File, FileInputStream}
 import java.nio.file.{Files, Paths}
 import java.util._
 
@@ -141,8 +142,15 @@ object RInterpreter {
   }
 
   def dataURI(file : String, mime : String) : String = {
-    val data: String = Source.fromFile(file).getLines().mkString("\n")
-    s"""data:${mime};base64,""" + 
StringUtils.newStringUtf8(Base64.encodeBase64(data.getBytes(), false))
+    val fp = new File(file)
+    val fdata = new Array[Byte](fp.length().toInt)
+    val fin = new BufferedInputStream(new FileInputStream(fp))
+    try {
+      fin.read(fdata)
+    } finally {
+      fin.close()
+    }
+    s"""data:${mime};base64,""" + 
StringUtils.newStringUtf8(Base64.encodeBase64(fdata, false))
   }
 
   // The purpose here is to deal with knitr producing HTML with script and css 
tags outside the <body>

Reply via email to