Browse Source

close的一些细节

research/10.0
alex.sung 6 years ago
parent
commit
071a75c731
  1. 51
      designer-base/src/main/java/com/fr/design/extra/PluginUtils.java
  2. 21
      designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java

51
designer-base/src/main/java/com/fr/design/extra/PluginUtils.java

@ -6,6 +6,7 @@ import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.plugin.PluginVerifyException;
import com.fr.plugin.basic.version.Version; import com.fr.plugin.basic.version.Version;
import com.fr.plugin.basic.version.VersionIntervalFactory; import com.fr.plugin.basic.version.VersionIntervalFactory;
import com.fr.plugin.context.PluginContext; import com.fr.plugin.context.PluginContext;
@ -18,6 +19,7 @@ import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.JOptionPane;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -82,12 +84,12 @@ public class PluginUtils {
return jsonArray.toString(); return jsonArray.toString();
} }
public static void downloadShopScripts(String id, Process<Double> p) throws Exception { public static boolean downloadShopScripts(String id, Process<Double> p) {
HttpClient httpClient = new HttpClient(getDownloadPath(id)); InputStream reader = null;
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { FileOutputStream writer = null;
InputStream reader = null; try {
FileOutputStream writer = null; HttpClient httpClient = new HttpClient(getDownloadPath(id));
try { if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
int totalSize = httpClient.getContentLength(); int totalSize = httpClient.getContentLength();
reader = httpClient.getResponseStream(); reader = httpClient.getResponseStream();
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE);
@ -103,19 +105,32 @@ public class PluginUtils {
totalBytesRead += bytesRead; totalBytesRead += bytesRead;
p.process(totalBytesRead / (double) totalSize); p.process(totalBytesRead / (double) totalSize);
} }
}catch (Exception e){ } else {
throw new Exception(); throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error"));
}finally {
if(null != reader){
reader.close();
}
if(null != writer){
writer.flush();
writer.close();
}
} }
} else { } catch (PluginVerifyException e) {
throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error")); JOptionPane.showMessageDialog(null, e.getMessage(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return false;
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
} finally {
closeStream(reader, writer);
}
return true;
}
private static void closeStream(InputStream reader, FileOutputStream writer){
try {
if (null != reader) {
reader.close();
}
if (null != writer) {
writer.flush();
writer.close();
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }

21
designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java

@ -259,21 +259,12 @@ public class WebViewDlgHelper {
new SwingWorker<Boolean, Void>() { new SwingWorker<Boolean, Void>() {
@Override @Override
protected Boolean doInBackground() throws Exception { protected Boolean doInBackground() throws Exception {
try { return PluginUtils.downloadShopScripts(scriptsId, new Process<Double>() {
PluginUtils.downloadShopScripts(scriptsId, new Process<Double>() { @Override
@Override public void process(Double integer) {
public void process(Double integer) { // 这个注释毫无意义,就是为了通过SonarQube
// 这个注释毫无意义,就是为了通过SonarQube }
} });
});
} catch (PluginVerifyException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return false;
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
}
return true;
} }
@Override @Override

Loading…
Cancel
Save