INT-3746: Polishing

- move `InputStream` test later
- add `name` for error messages
- add test
This commit is contained in:
Gary Russell
2019-07-23 13:00:18 -04:00
parent 89e1eb35b9
commit d2eee913d7
2 changed files with 17 additions and 5 deletions

View File

@@ -490,10 +490,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
Object payload = message.getPayload();
InputStream dataInputStream = null;
String name = null;
if (payload instanceof InputStream) {
dataInputStream = (InputStream) payload;
}
else if (payload instanceof File) {
if (payload instanceof File) {
File inputFile = (File) payload;
if (inputFile.exists()) {
dataInputStream = new BufferedInputStream(new FileInputStream(inputFile));
@@ -512,9 +509,13 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
}
dataInputStream = new ByteArrayInputStream(bytes);
}
else if (payload instanceof InputStream) {
dataInputStream = (InputStream) payload;
name = "InputStream payload";
}
else {
throw new IllegalArgumentException("Unsupported payload type. The only supported payloads are " +
"java.io.File, java.lang.String, byte[] and InputStream");
"java.io.File, java.lang.String, byte[], and InputStream");
}
if (dataInputStream == null) {
return null;