Skip to content

Commit d2eee91

Browse files
committed
INT-3746: Polishing
- move `InputStream` test later - add `name` for error messages - add test
1 parent 89e1eb3 commit d2eee91

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,7 @@ private StreamHolder payloadToInputStream(Message<?> message) throws MessageDeli
490490
Object payload = message.getPayload();
491491
InputStream dataInputStream = null;
492492
String name = null;
493-
if (payload instanceof InputStream) {
494-
dataInputStream = (InputStream) payload;
495-
}
496-
else if (payload instanceof File) {
493+
if (payload instanceof File) {
497494
File inputFile = (File) payload;
498495
if (inputFile.exists()) {
499496
dataInputStream = new BufferedInputStream(new FileInputStream(inputFile));
@@ -512,9 +509,13 @@ else if (payload instanceof byte[] || payload instanceof String) {
512509
}
513510
dataInputStream = new ByteArrayInputStream(bytes);
514511
}
512+
else if (payload instanceof InputStream) {
513+
dataInputStream = (InputStream) payload;
514+
name = "InputStream payload";
515+
}
515516
else {
516517
throw new IllegalArgumentException("Unsupported payload type. The only supported payloads are " +
517-
"java.io.File, java.lang.String, byte[] and InputStream");
518+
"java.io.File, java.lang.String, byte[], and InputStream");
518519
}
519520
if (dataInputStream == null) {
520521
return null;

spring-integration-file/src/test/java/org/springframework/integration/file/remote/RemoteFileTemplateTests.java

+11
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
import static org.mockito.Mockito.verify;
2626
import static org.mockito.Mockito.when;
2727

28+
import java.io.ByteArrayInputStream;
2829
import java.io.File;
30+
import java.io.IOException;
2931
import java.io.InputStream;
3032

3133
import org.junit.Before;
3234
import org.junit.Rule;
3335
import org.junit.Test;
3436
import org.junit.rules.TemporaryFolder;
37+
import org.mockito.Mockito;
3538

3639
import org.springframework.beans.factory.BeanFactory;
3740
import org.springframework.expression.common.LiteralExpression;
@@ -119,4 +122,12 @@ public void testIgnoreNotExists() throws Exception {
119122
verify(this.session).write(any(InputStream.class), anyString());
120123
}
121124

125+
@Test
126+
public void testStream() throws IOException {
127+
ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
128+
this.template.send(new GenericMessage<InputStream>(stream),
129+
FileExistsMode.IGNORE);
130+
verify(this.session).write(Mockito.eq(stream), Mockito.any());
131+
}
132+
122133
}

0 commit comments

Comments
 (0)