BAEL-4088: addressed code review comments.
This commit is contained in:
parent
15535cf0cf
commit
0f36d61b67
|
@ -15,11 +15,17 @@
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<commons-io.version>2.6</commons-io.version>
|
||||||
<junit.version>4.12</junit.version>
|
<junit.version>4.12</junit.version>
|
||||||
<org.springframework.spring-mock.version>2.0.8</org.springframework.spring-mock.version>
|
<org.springframework.spring-mock.version>2.0.8</org.springframework.spring-mock.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>${commons-io.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
|
|
|
@ -6,6 +6,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -23,11 +25,11 @@ public class ConvertMultipartFileExample {
|
||||||
|
|
||||||
File file = new File("src/main/resources/targetFile.tmp");
|
File file = new File("src/main/resources/targetFile.tmp");
|
||||||
|
|
||||||
OutputStream os = new FileOutputStream(file);
|
try (OutputStream os = new FileOutputStream(file)) {
|
||||||
|
os.write(multipartFile.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
os.write(multipartFile.getBytes());
|
Assert.assertEquals(FileUtils.readFileToString(new File("src/main/resources/targetFile.tmp"), "UTF-8"), "Hello World");
|
||||||
|
|
||||||
os.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,10 +46,12 @@ public class ConvertMultipartFileExample {
|
||||||
initialStream.read(buffer);
|
initialStream.read(buffer);
|
||||||
|
|
||||||
File targetFile = new File("src/main/resources/targetFile.tmp");
|
File targetFile = new File("src/main/resources/targetFile.tmp");
|
||||||
OutputStream outStream = new FileOutputStream(targetFile);
|
|
||||||
outStream.write(buffer);
|
|
||||||
|
|
||||||
outStream.close();
|
try (OutputStream outStream = new FileOutputStream(targetFile)) {
|
||||||
|
outStream.write(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(FileUtils.readFileToString(new File("src/main/resources/targetFile.tmp"), "UTF-8"), "Hello World");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,5 +66,7 @@ public class ConvertMultipartFileExample {
|
||||||
File file = new File("src/main/resources/targetFile.tmp");
|
File file = new File("src/main/resources/targetFile.tmp");
|
||||||
|
|
||||||
multipartFile.transferTo(file);
|
multipartFile.transferTo(file);
|
||||||
|
|
||||||
|
Assert.assertEquals(FileUtils.readFileToString(new File("src/main/resources/targetFile.tmp"), "UTF-8"), "Hello World");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue