From ee5c24ef12a66c4d2f8f4f2c3517ea2ab89ca8b0 Mon Sep 17 00:00:00 2001 From: neil <459208047@qq.com> Date: Thu, 6 Sep 2018 10:05:26 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-10719=20=E6=A8=A1=E6=9D=BF=E4=BF=9D?= =?UTF-8?q?=E5=AD=980kb,=20=E6=94=AF=E6=8C=81=E9=9B=86=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/file/FileNodeFILE.java | 3 +- .../fr/file/WorkResourceTempRenameStream.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/file/WorkResourceTempRenameStream.java diff --git a/designer-base/src/main/java/com/fr/file/FileNodeFILE.java b/designer-base/src/main/java/com/fr/file/FileNodeFILE.java index 04016c5039..c7c6bf2b34 100644 --- a/designer-base/src/main/java/com/fr/file/FileNodeFILE.java +++ b/designer-base/src/main/java/com/fr/file/FileNodeFILE.java @@ -14,7 +14,6 @@ import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.project.ProjectConstants; import com.fr.workspace.WorkContext; -import com.fr.workspace.resource.WorkResourceOutputStream; import javax.swing.Icon; import java.io.ByteArrayInputStream; @@ -381,7 +380,7 @@ public class FileNodeFILE implements FILE { if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { return null; } - return new WorkResourceOutputStream(envPath); + return new WorkResourceTempRenameStream(envPath); } /** diff --git a/designer-base/src/main/java/com/fr/file/WorkResourceTempRenameStream.java b/designer-base/src/main/java/com/fr/file/WorkResourceTempRenameStream.java new file mode 100644 index 0000000000..576239b354 --- /dev/null +++ b/designer-base/src/main/java/com/fr/file/WorkResourceTempRenameStream.java @@ -0,0 +1,39 @@ +package com.fr.file; + +import com.fr.stable.ArrayUtils; +import com.fr.stable.project.ProjectConstants; +import com.fr.workspace.WorkContext; +import com.fr.workspace.resource.WorkResource; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * 这个流会先输出临时文件到服务器. + * 然后再操作服务器对文件进行重命名. + * 用于设计器本地和远程修改模板. + */ +public class WorkResourceTempRenameStream extends ByteArrayOutputStream { + + private String path; + + public WorkResourceTempRenameStream(String path) { + this.path = path; + } + + @Override + public void close() throws IOException { + //写到给定的path上去 + byte[] content = super.toByteArray(); + if (ArrayUtils.isEmpty(content)) { + return; + } + + String tmpPath = path + ProjectConstants.TEMP_SUFFIX; + WorkResource resource = WorkContext.getWorkResource(); + // 输出临时文件到服务器 + resource.write(tmpPath, content); + // 重命名文件 + resource.rename(tmpPath, path); + } +}