Skip to content

Commit 5ad304a

Browse files
garyrussellartembilan
authored andcommitted
INT-4374: TCP Fix elastic raw deserializer
JIRA: https://jira.spring.io/browse/INT-4374 Detect end of stream to prevent emitting an empty byte[] payload.
1 parent f21f810 commit 5ad304a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayElasticRawDeserializer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,9 @@ public ByteArrayElasticRawDeserializer(int initialBufferSize) {
5656
@Override
5757
public byte[] deserialize(InputStream inputStream) throws IOException {
5858
ByteArrayOutputStream out = new ByteArrayOutputStream(this.initialBufferSize);
59-
StreamUtils.copy(inputStream, out);
59+
if (StreamUtils.copy(inputStream, out) == 0) {
60+
throw new SoftEndOfStreamException("Stream closed with no data");
61+
}
6062
out.close();
6163
return out.toByteArray();
6264
}

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/serializer/DeserializationTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -153,6 +153,13 @@ public void testReadRawElastic() throws Exception {
153153
byte[] out = serializer.deserialize(socket.getInputStream());
154154
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
155155
new String(out));
156+
try {
157+
serializer.deserialize(socket.getInputStream());
158+
fail("Expected end of Stream");
159+
}
160+
catch (SoftEndOfStreamException e) {
161+
// NOSONAR
162+
}
156163
server.close();
157164
}
158165

0 commit comments

Comments
 (0)