Browse Source

无JIRA任务,sonar问题修复

research/10.0
alex.sung 5 years ago
parent
commit
ed5a2a5347
  1. 13
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 11
      designer-base/src/main/java/com/fr/design/RestartHelper.java
  3. 43
      designer-base/src/main/java/com/fr/design/extra/PluginUtils.java
  4. 10
      designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java
  5. 7
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/CodeTemplateManager.java

13
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -310,8 +310,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
}
private void createEnvFile(File envFile) {
FileWriter fileWriter = null;
try {
FileWriter fileWriter = new FileWriter(envFile);
fileWriter = new FileWriter(envFile);
File oldEnvFile = new File(ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "6-1" + "Env.xml");
File envFile80 = new File(getEnvHome(VERSION_80) + File.separator + getEnvFile().getName());
if (oldEnvFile.exists()) {
@ -327,9 +328,17 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
Utils.copyCharTo(stringReader, fileWriter);
stringReader.close();
}
fileWriter.close();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
if (null != fileWriter) {
try {
fileWriter.close();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
}

11
designer-base/src/main/java/com/fr/design/RestartHelper.java

@ -154,12 +154,12 @@ public class RestartHelper {
deleteWhenDebug();
return;
}
RandomAccessFile randomAccessFile = null;
try {
try {
File restartLockFile = new File(StableUtils.pathJoin(StableUtils.getInstallHome(), "restart.lock"));
StableUtils.makesureFileExist(restartLockFile);
RandomAccessFile randomAccessFile = new RandomAccessFile(restartLockFile,"rw");
randomAccessFile = new RandomAccessFile(restartLockFile,"rw");
FileChannel restartLockFC = randomAccessFile.getChannel();
FileLock restartLock = restartLockFC.tryLock();
if(restartLock == null) {
@ -176,6 +176,13 @@ public class RestartHelper {
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
try {
if (null != randomAccessFile) {
randomAccessFile.close();
}
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
DesignerContext.getDesignerFrame().exit();
}
}

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

@ -85,24 +85,35 @@ public class PluginUtils {
public static void downloadShopScripts(String id, Process<Double> p) throws Exception {
HttpClient httpClient = new HttpClient(getDownloadPath(id));
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
int totalSize = httpClient.getContentLength();
InputStream reader = httpClient.getResponseStream();
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE);
StableUtils.makesureFileExist(new File(temp));
FileOutputStream writer = new FileOutputStream(temp);
byte[] buffer = new byte[PluginConstants.BYTES_NUM];
int bytesRead = 0;
int totalBytesRead = 0;
InputStream reader = null;
FileOutputStream writer = null;
try {
int totalSize = httpClient.getContentLength();
reader = httpClient.getResponseStream();
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE);
StableUtils.makesureFileExist(new File(temp));
writer = new FileOutputStream(temp);
byte[] buffer = new byte[PluginConstants.BYTES_NUM];
int bytesRead = 0;
int totalBytesRead = 0;
while ((bytesRead = reader.read(buffer)) > 0) {
writer.write(buffer, 0, bytesRead);
buffer = new byte[PluginConstants.BYTES_NUM];
totalBytesRead += bytesRead;
p.process(totalBytesRead / (double) totalSize);
while ((bytesRead = reader.read(buffer)) > 0) {
writer.write(buffer, 0, bytesRead);
buffer = new byte[PluginConstants.BYTES_NUM];
totalBytesRead += bytesRead;
p.process(totalBytesRead / (double) totalSize);
}
}catch (Exception e){
throw new Exception();
}finally {
if(null != reader){
reader.close();
}
if(null != writer){
writer.flush();
writer.close();
}
}
reader.close();
writer.flush();
writer.close();
} else {
throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error"));
}

10
designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java

@ -174,7 +174,7 @@ public final class FunctionConstants {
jarPath = StringUtils.perfectStart(jarPath, "/");
}
ZipFile zip;
ZipFile zip = null;
try {
zip = new ZipFile(jarPath);
Enumeration entries = zip.entries();
@ -193,6 +193,14 @@ public final class FunctionConstants {
}
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
if(null != zip){
try {
zip.close();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
} else {
File dir = new File(filePath);

7
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/CodeTemplateManager.java

@ -276,8 +276,9 @@ public class CodeTemplateManager {
temp.addAll(templates);
for (int i=0; i<newCount; i++) {
XMLDecoder d = null;
try {
XMLDecoder d = new XMLDecoder(new BufferedInputStream(
d = new XMLDecoder(new BufferedInputStream(
new FileInputStream(files[i])));
Object obj = d.readObject();
if (!(obj instanceof CodeTemplate)) {
@ -291,6 +292,10 @@ public class CodeTemplateManager {
// an XML file not in the format expected by XMLDecoder.
// (e.g. CodeTemplates in an old format).
e.printStackTrace();
} finally {
if(null != d){
d.close();
}
}
}
templates = temp;

Loading…
Cancel
Save