[#4476]use more stable apis to create InputStream (#4478)

diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownloadSchema.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownloadSchema.java
index 4e5fc96..f1ba4b8 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownloadSchema.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDownloadSchema.java
@@ -42,6 +42,7 @@
   @Override
   public void testRestTransport() throws Exception {
     testDownloadFileAndDeleted();
+    testDownloadFileAndDeletedCN();
     testDownloadFileNotDeleted();
     testDownloadFileWithNull();
     testSetContentTypeByResponseEntity();
@@ -97,6 +98,19 @@
     TestMgr.check(exists, false);
   }
 
+  private void testDownloadFileAndDeletedCN() throws Exception {
+    RestOperations restTemplate = RestTemplateBuilder.create();
+    ReadStreamPart readStreamPart = restTemplate
+        .getForObject("servicecomb://springmvc/download/deleteAfterFinished?content={1}&fileName={2}",
+            ReadStreamPart.class, "hello", "中文");
+    String hello = readStreamPart.saveAsString().get();
+    TestMgr.check(hello, "hello");
+
+    boolean exists = restTemplate
+        .getForObject("servicecomb://springmvc/download/assertLastFileDeleted", boolean.class);
+    TestMgr.check(exists, false);
+  }
+
   private void testDownloadFileWithNull() throws Exception {
     RestOperations restTemplate = RestTemplateBuilder.create();
     ReadStreamPart readStreamPart = restTemplate
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestUploadSchema.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestUploadSchema.java
index 344b431..0e6d810 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestUploadSchema.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestUploadSchema.java
@@ -59,6 +59,7 @@
     testUploadMultiBigFiles();
     testFileUploadMultiRpc();
     testUploadFileAndAttribute();
+    testUploadFileAndAttributeCN();
     testUploadFileRequestPartAttribute();
     testUploadFileRequestPartAttributeList();
   }
@@ -127,6 +128,23 @@
     TestMgr.check("hi test", result);
   }
 
+  private void testUploadFileAndAttributeCN() throws Exception {
+    RestOperations template = RestTemplateBuilder.create();
+    Map<String, Object> map = new HashMap<>();
+    String message = "hi";
+    File file = File.createTempFile("中文名称", ".txt");
+    FileUtils.writeStringToFile(file, "test", StandardCharsets.UTF_8, false);
+
+    map.put("file", new FileSystemResource(file));
+    map.put("attribute", message);
+    HttpHeaders headers = new HttpHeaders();
+    headers.setContentType(org.springframework.http.MediaType.MULTIPART_FORM_DATA);
+    String result = template.postForObject("servicecomb://springmvc/upload/uploadFileAndAttribute",
+        new HttpEntity<>(map, headers), String.class);
+    TestMgr.check("hi test", result);
+  }
+
+
   private void testUploadFileRequestPartAttribute() throws Exception {
     RestOperations template = RestTemplateBuilder.create();
     Map<String, Object> map = new HashMap<>();
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DownloadSchema.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DownloadSchema.java
index 5db71e5..d73824f 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DownloadSchema.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DownloadSchema.java
@@ -57,8 +57,15 @@
   }
 
   @GetMapping(path = "/deleteAfterFinished")
-  public ResponseEntity<Part> deleteAfterFinished(@RequestParam("content") String content) throws IOException {
-    File file = createTempFile(content);
+  public ResponseEntity<Part> deleteAfterFinished(@RequestParam("content") String content,
+      @RequestParam(value = "fileName", required = false) String fileName) throws IOException {
+    File file;
+
+    if (StringUtils.isNotEmpty(fileName)) {
+      file = createTempFile(fileName, content);
+    } else {
+      file = createTempFile(content);
+    }
 
     return ResponseEntity
         .ok()
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/part/FilePart.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/part/FilePart.java
index d44c40b..1bd9ddf 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/part/FilePart.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/part/FilePart.java
@@ -18,9 +18,9 @@
 package org.apache.servicecomb.foundation.common.part;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 
 import org.apache.commons.io.FileUtils;
 
@@ -41,7 +41,7 @@
 
   @Override
   public InputStream getInputStream() throws IOException {
-    return new FileInputStream(file);
+    return Files.newInputStream(file.toPath());
   }
 
   @Override
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/FileUploadPart.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/FileUploadPart.java
index a444495..9e72d64 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/FileUploadPart.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/FileUploadPart.java
@@ -18,9 +18,9 @@
 package org.apache.servicecomb.foundation.vertx.http;

 

 import java.io.File;

-import java.io.FileInputStream;

 import java.io.IOException;

 import java.io.InputStream;

+import java.nio.file.Files;

 

 import org.apache.commons.io.FileUtils;

 import org.apache.servicecomb.foundation.common.part.AbstractPart;

@@ -36,7 +36,7 @@
 

   @Override

   public InputStream getInputStream() throws IOException {

-    return new FileInputStream(fileUpload.uploadedFileName());

+    return Files.newInputStream(new File(fileUpload.uploadedFileName()).toPath());

   }

 

   @Override