INT-1280 (partial) - Moved Converter implementations back to root package
This commit is contained in:
@@ -14,16 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.commons.serializer.java;
|
||||
package org.springframework.commons.serializer;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.commons.serializer.DeserializationFailureException;
|
||||
import org.springframework.commons.serializer.java.JavaStreamingConverter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
/**
|
||||
* Delegates to a {@link JavaStreamingConverter} to deserialize data
|
||||
* Delegates to a {@link InputStreamingConverter} (default is
|
||||
* {@link JavaStreamingConverter}} to deserialize data
|
||||
* in a byte[] to an object.
|
||||
*
|
||||
* @author Gary Russell
|
||||
@@ -32,12 +33,13 @@ import org.springframework.core.convert.converter.Converter;
|
||||
*/
|
||||
public class DeserializingConverter implements Converter<byte[], Object> {
|
||||
|
||||
private JavaStreamingConverter converter = new JavaStreamingConverter();
|
||||
private InputStreamingConverter<Object> streamingConverter
|
||||
= new JavaStreamingConverter();
|
||||
|
||||
public Object convert(byte[] source) {
|
||||
ByteArrayInputStream byteStream = new ByteArrayInputStream(source);
|
||||
try {
|
||||
return converter.convert(byteStream);
|
||||
return streamingConverter.convert(byteStream);
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
@@ -48,5 +50,13 @@ public class DeserializingConverter implements Converter<byte[], Object> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the default {@link JavaStreamingConverter}
|
||||
* @param streamingConverter the streamingConverter to set
|
||||
*/
|
||||
public void setStreamingConverter(InputStreamingConverter<Object> streamingConverter) {
|
||||
this.streamingConverter = streamingConverter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,18 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.commons.serializer.java;
|
||||
package org.springframework.commons.serializer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.commons.serializer.SerializationFailureException;
|
||||
import org.springframework.commons.serializer.java.JavaStreamingConverter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Delegates to a {@link JavaStreamingConverter} to serialize an object
|
||||
* to a byte[]. Source object must implement {@link Serializable}.
|
||||
* Delegates to a {@link OutputStreamingConverter} (default is
|
||||
* {@link JavaStreamingConverter}) to serialize an object
|
||||
* to a byte[].
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
@@ -33,18 +34,26 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class SerializingConverter implements Converter<Object, byte[]> {
|
||||
|
||||
private JavaStreamingConverter converter = new JavaStreamingConverter();
|
||||
private OutputStreamingConverter<Object> streamingConverter
|
||||
= new JavaStreamingConverter();
|
||||
|
||||
public byte[] convert(Object source) {
|
||||
Assert.isTrue(source instanceof Serializable, this.getClass().getName()
|
||||
+ " requires a Serializable payload, but received [" + source.getClass().getName() + "]");
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
this.converter.convert(source, byteStream);
|
||||
this.streamingConverter.convert(source, byteStream);
|
||||
return byteStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new SerializationFailureException("Failed to serialize", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the default {@link JavaStreamingConverter}
|
||||
* @param streamingConverter the streamingConverter to set
|
||||
*/
|
||||
public void setStreamingConverter(
|
||||
OutputStreamingConverter<Object> streamingConverter) {
|
||||
this.streamingConverter = streamingConverter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,9 +21,11 @@ import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.commons.serializer.InputStreamingConverter;
|
||||
import org.springframework.commons.serializer.OutputStreamingConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,8 +53,14 @@ public class JavaStreamingConverter
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Source object must implement {@link Serializable}.
|
||||
*/
|
||||
public void convert(Object object, OutputStream outputStream)
|
||||
throws IOException {
|
||||
Assert.isTrue(object instanceof Serializable, this.getClass().getName()
|
||||
+ " requires a Serializable payload, but received [" +
|
||||
object.getClass().getName() + "]");
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
|
||||
objectOutputStream.writeObject(object);
|
||||
objectOutputStream.flush();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/**
|
||||
* Implementations of In/Out JavaStreamingConverter and
|
||||
* Converter using standard Java Serialization.
|
||||
* Implementation of In/Out JavaStreamingConverter.
|
||||
*/
|
||||
package org.springframework.commons.serializer.java;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Root package for Spring commons' serializer interfaces and implementations.
|
||||
* Provides an abstraction over various serialization techniques.
|
||||
* Includes exceptions for serialization and deserialization failures.
|
||||
* Actual (de)serializers are in subpackages.
|
||||
*/
|
||||
package org.springframework.commons.serializer;
|
||||
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package org.springframework.integration.transformer;
|
||||
|
||||
import org.springframework.commons.serializer.java.DeserializingConverter;
|
||||
import org.springframework.commons.serializer.DeserializingConverter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Transformer that deserializes the inbound byte array payload to an object by delegating to a
|
||||
* Converter<byte[], Object>. Default delegate is a {@link DeserializingConverter}.
|
||||
* Converter<byte[], Object>. Default delegate is a {@link DeserializingConverter} using
|
||||
* Java serialization.
|
||||
*
|
||||
* <p>The byte array payload must be a result of equivalent serialization.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
|
||||
package org.springframework.integration.transformer;
|
||||
|
||||
import org.springframework.commons.serializer.java.SerializingConverter;
|
||||
import org.springframework.commons.serializer.SerializingConverter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Transformer that serializes the inbound payload into a byte array by delegating to a
|
||||
* Converter<Object, byte[]>. Default delegate is a {@link SerializingConverter}.
|
||||
* Converter<Object, byte[]>. Default delegate is a {@link SerializingConverter} using
|
||||
* Java serialization.
|
||||
*
|
||||
* <p>The payload instance must be Serializable if the default converter is used.
|
||||
*
|
||||
|
||||
@@ -22,8 +22,6 @@ import static org.junit.Assert.fail;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.commons.serializer.java.DeserializingConverter;
|
||||
import org.springframework.commons.serializer.java.SerializingConverter;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user