diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayElasticRawDeserializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayElasticRawDeserializer.java index 446fd2a1b9..8d10106d76 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayElasticRawDeserializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayElasticRawDeserializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,9 @@ public class ByteArrayElasticRawDeserializer implements Deserializer { @Override public byte[] deserialize(InputStream inputStream) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(this.initialBufferSize); - StreamUtils.copy(inputStream, out); + if (StreamUtils.copy(inputStream, out) == 0) { + throw new SoftEndOfStreamException("Stream closed with no data"); + } out.close(); return out.toByteArray(); } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/serializer/DeserializationTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/serializer/DeserializationTests.java index c0c96c1f2d..1d38a6116c 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/serializer/DeserializationTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/serializer/DeserializationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,6 +153,13 @@ public class DeserializationTests { byte[] out = serializer.deserialize(socket.getInputStream()); assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING, new String(out)); + try { + serializer.deserialize(socket.getInputStream()); + fail("Expected end of Stream"); + } + catch (SoftEndOfStreamException e) { + // NOSONAR + } server.close(); }