Class CompositeCodec
java.lang.Object
org.springframework.integration.codec.CompositeCodec
- All Implemented Interfaces:
Codec
An implementation of
Codec
that combines multiple codecs into a single codec,
delegating encoding and decoding operations to the appropriate type-specific codec.
This implementation associates object types with their appropriate codecs while providing a fallback default codec
for unregistered types.
This class uses ClassUtils.findClosestMatch
to select the appropriate codec for a given object type.
When multiple codecs match an object type, ClassUtils.findClosestMatch
offers the
failOnTie
option. If failOnTie
is false
, it will return any one of the matching codecs.
If failOnTie
is true
and multiple codecs match, it will throw an IllegalStateException
.
CompositeCodec
sets failOnTie
to true
, so if multiple codecs match, an
IllegalStateException
is thrown.- Since:
- 4.2
- Author:
- David Turanski, Glenn Renfro
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
Decode an object of a given type.<T> T
decode
(InputStream inputStream, Class<T> type) Decode an object of a given type.byte[]
Encode an object to a byte array.void
encode
(Object object, OutputStream outputStream) Encode (encode) an object to an OutputStream.
-
Constructor Details
-
CompositeCodec
-
-
Method Details
-
encode
Description copied from interface:Codec
Encode (encode) an object to an OutputStream.- Specified by:
encode
in interfaceCodec
- Parameters:
object
- the object to encodeoutputStream
- the OutputStream- Throws:
IOException
- if the operation fails
-
encode
Description copied from interface:Codec
Encode an object to a byte array.- Specified by:
encode
in interfaceCodec
- Parameters:
object
- the object to encode- Returns:
- the bytes
- Throws:
IOException
- if the operation fails
-
decode
Description copied from interface:Codec
Decode an object of a given type.- Specified by:
decode
in interfaceCodec
- Type Parameters:
T
- the object's type- Parameters:
inputStream
- the input stream containing the encoded objecttype
- the object's class- Returns:
- the object
- Throws:
IOException
- if the operation fails
-
decode
Description copied from interface:Codec
Decode an object of a given type.- Specified by:
decode
in interfaceCodec
- Type Parameters:
T
- the object's type- Parameters:
bytes
- the byte array containing the encoded objecttype
- the object's class- Returns:
- the object
- Throws:
IOException
- if the operation fails
-