zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject zeppelin git commit: [MINOR] Refactor to modern apis
Date Sat, 28 Jan 2017 22:28:20 GMT
Repository: zeppelin
Updated Branches:
  refs/heads/master 5f3f28916 -> fe2fffe08


[MINOR] Refactor to modern apis

### What is this PR for?
Use modern api to write less and try-with-resources to close file in case of errors

### What type of PR is it?
Refactoring

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

Author: Igor Drozdov <igor_drozdov@epam.com>

Closes #1949 from DrIgor/file-loading-refactoring and squashes the following commits:

d1ee8a1 [Igor Drozdov] Refactor to modern apis


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

Branch: refs/heads/master
Commit: fe2fffe083d3d38ebacaf9043eddc9fd353e0d26
Parents: 5f3f289
Author: Igor Drozdov <igor_drozdov@epam.com>
Authored: Thu Jan 26 16:22:45 2017 +0300
Committer: Lee moon soo <moon@apache.org>
Committed: Sun Jan 29 07:28:19 2017 +0900

----------------------------------------------------------------------
 .../interpreter/InterpreterFactory.java         | 30 +++++++-------------
 1 file changed, 10 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/fe2fffe0/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
index e065742..bb43fa4 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
@@ -18,7 +18,6 @@
 package org.apache.zeppelin.interpreter;
 
 import com.google.common.base.Joiner;
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -27,12 +26,14 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
+import java.io.Reader;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Type;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -365,27 +366,15 @@ public class InterpreterFactory implements InterpreterGroupFactory {
   }
 
   private void loadFromFile() throws IOException {
-    File settingFile = new File(conf.getInterpreterSettingPath());
-    if (!settingFile.exists()) {
+    Path settingFile = Paths.get(conf.getInterpreterSettingPath());
+    if (!Files.exists(settingFile)) {
       // nothing to read
       return;
     }
-    FileInputStream fis = new FileInputStream(settingFile);
-    InputStreamReader isr = new InputStreamReader(fis);
-    BufferedReader bufferedReader = new BufferedReader(isr);
-    StringBuilder sb = new StringBuilder();
-    InterpreterSetting interpreterSettingObject;
-    String depClassPath = StringUtils.EMPTY;
-    String line;
-    while ((line = bufferedReader.readLine()) != null) {
-      sb.append(line);
+    InterpreterInfoSaving infoSaving;
+    try (Reader json = Files.newBufferedReader(settingFile, StandardCharsets.UTF_8)) {
+      infoSaving = gson.fromJson(json, InterpreterInfoSaving.class);
     }
-    isr.close();
-    fis.close();
-
-    String json = sb.toString();
-    InterpreterInfoSaving infoSaving = gson.fromJson(json, InterpreterInfoSaving.class);
-
     for (String k : infoSaving.interpreterSettings.keySet()) {
       InterpreterSetting setting = infoSaving.interpreterSettings.get(k);
       List<InterpreterInfo> infos = setting.getInterpreterInfos();
@@ -405,13 +394,14 @@ public class InterpreterFactory implements InterpreterGroupFactory {
       setting.getOption().setRemote(true);
 
       // Update transient information from InterpreterSettingRef
-      interpreterSettingObject = interpreterSettingsRef.get(setting.getGroup());
+      InterpreterSetting interpreterSettingObject =
+          interpreterSettingsRef.get(setting.getGroup());
       if (interpreterSettingObject == null) {
         logger.warn("can't get InterpreterSetting " +
             "Information From loaded Interpreter Setting Ref - {} ", setting.getGroup());
         continue;
       }
-      depClassPath = interpreterSettingObject.getPath();
+      String depClassPath = interpreterSettingObject.getPath();
       setting.setPath(depClassPath);
 
       for (InterpreterInfo info : infos) {


Mime
View raw message