diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java index 99f66a1b3c..f27255638b 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java @@ -21,18 +21,20 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; +import org.springframework.util.Assert; + /** * Reads data in an InputStream to a byte[]; data must be preceded by * a binary length (network byte order, not included in resulting byte[]). - * + *

* Writes a byte[] to an OutputStream after a binary length. * The length field contains the length of data following the length * field. (network byte order). - * + *

* The default length field is a 4 byte signed integer. During deserialization, * negative values will be rejected. * Other options are an unsigned byte, and unsigned short. - * + *

* For other header formats, override {@link #readHeader(InputStream)} and * {@link #writeHeader(OutputStream, int)}. * @@ -80,11 +82,10 @@ public class ByteArrayLengthHeaderSerializer extends AbstractByteArraySerializer * @param headerSize The header size. */ public ByteArrayLengthHeaderSerializer(int headerSize) { - if (headerSize != HEADER_SIZE_INT && - headerSize != HEADER_SIZE_UNSIGNED_BYTE && - headerSize != HEADER_SIZE_UNSIGNED_SHORT) { - throw new IllegalArgumentException("Illegal header size: " + headerSize); - } + Assert.isTrue(headerSize == HEADER_SIZE_INT + || headerSize == HEADER_SIZE_UNSIGNED_BYTE + || headerSize == HEADER_SIZE_UNSIGNED_SHORT, + () -> "Illegal header size: " + headerSize); this.headerSize = headerSize; } @@ -177,6 +178,7 @@ public class ByteArrayLengthHeaderSerializer extends AbstractByteArraySerializer */ protected int read(InputStream inputStream, byte[] buffer, boolean header) throws IOException { + int lengthRead = 0; int needed = buffer.length; while (lengthRead < needed) { @@ -247,9 +249,7 @@ public class ByteArrayLengthHeaderSerializer extends AbstractByteArraySerializer case HEADER_SIZE_INT: int messageLength = ByteBuffer.wrap(lengthPart).getInt(); if (messageLength < 0) { - throw new IllegalArgumentException("Length header: " - + messageLength - + " is negative"); + throw new IllegalArgumentException("Length header: " + messageLength + " is negative"); } return messageLength; case HEADER_SIZE_UNSIGNED_BYTE: @@ -260,8 +260,8 @@ public class ByteArrayLengthHeaderSerializer extends AbstractByteArraySerializer throw new IllegalArgumentException("Bad header size: " + this.headerSize); } } - catch (SoftEndOfStreamException e) { // NOSONAR catch and throw - throw e; // it's an IO exception and we don't want an event for this + catch (SoftEndOfStreamException ex) { // NOSONAR catch and throw + throw ex; // it's an IO exception, and we don't want an event for this } catch (IOException | RuntimeException ex) { publishEvent(ex, lengthPart, -1); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLfSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLfSerializer.java index 0fe8622068..3eed01faa6 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLfSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLfSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -17,7 +17,11 @@ package org.springframework.integration.ip.tcp.serializer; /** + * The {@link ByteArraySingleTerminatorSerializer} extension for the {@code LF} + * message delimiter. + * * @author Gary Russell + * * @since 2.2 * */ diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/MapJsonSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/MapJsonSerializer.java index 086e3b19fb..8e4910f9fb 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/MapJsonSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/MapJsonSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -33,11 +33,11 @@ import org.springframework.util.Assert; /** * Serializes a {@link Map} as JSON. Deserializes JSON to - * a {@link Map}. The default {@link org.springframework.integration.support.json.JsonObjectMapperProvider#newInstance()} can be + * a {@link Map}. The default {@link JsonObjectMapperProvider#newInstance()} can be * overridden using {@link #setJsonObjectMapper(JsonObjectMapper)}. *

* The JSON deserializer can't delimit multiple JSON - * objects. Therefore another (de)serializer is used to + * objects. Therefore, another (de)serializer is used to * apply structure to the stream. By default, this is a * simple {@link ByteArrayLfSerializer}, which inserts/expects * LF (0x0a) between messages. diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/SoftEndOfStreamException.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/SoftEndOfStreamException.java index 4ee15c4536..7ff7a2bd81 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/SoftEndOfStreamException.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/SoftEndOfStreamException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -16,6 +16,8 @@ package org.springframework.integration.ip.tcp.serializer; +import java.io.Serial; + /** * Used to communicate that a stream has closed, but between logical * messages. @@ -27,6 +29,7 @@ package org.springframework.integration.ip.tcp.serializer; */ public class SoftEndOfStreamException extends RuntimeException { + @Serial private static final long serialVersionUID = -2209857413498073058L; /** diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/TcpDeserializationExceptionEvent.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/TcpDeserializationExceptionEvent.java index 1214703d1e..6af343bf51 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/TcpDeserializationExceptionEvent.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/TcpDeserializationExceptionEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2024 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. @@ -16,6 +16,8 @@ package org.springframework.integration.ip.tcp.serializer; +import java.io.Serial; + import org.springframework.integration.ip.event.IpIntegrationEvent; /** @@ -29,6 +31,7 @@ import org.springframework.integration.ip.event.IpIntegrationEvent; */ public class TcpDeserializationExceptionEvent extends IpIntegrationEvent { + @Serial private static final long serialVersionUID = 8812537718016054732L; private final byte[] buffer;