use of org.mule.runtime.api.serialization.SerializationException in project mule by mulesoft.
the class GZipUncompressTransformer method doTransform.
@Override
public Object doTransform(Object src, Charset outputEncoding) throws TransformerException {
try {
if (src instanceof CursorStreamProvider) {
return getStrategy().uncompressInputStream(((CursorStreamProvider) src).openCursor());
}
if (src instanceof InputStream) {
return getStrategy().uncompressInputStream((InputStream) src);
} else {
byte[] buffer = getStrategy().uncompressByteArray((byte[]) src);
DataType returnDataType = getReturnDataType();
// If a return type has been specified, then deserialize the uncompressed byte array.
if (DataType.STRING.isCompatibleWith(returnDataType)) {
return new String(buffer, outputEncoding);
} else if (!DataType.OBJECT.isCompatibleWith(returnDataType) && !DataType.BYTE_ARRAY.isCompatibleWith(returnDataType)) {
try {
return muleContext.getObjectSerializer().getExternalProtocol().deserialize(buffer);
} catch (SerializationException e) {
throw new TransformerException(this, e);
}
} else {
// First try to deserialize the byte array. If it can be deserialized, then it was originally serialized.
try {
return muleContext.getObjectSerializer().getExternalProtocol().deserialize(buffer);
} catch (SerializationException e) {
// If it fails, ignore it. We assume it was not serialized in the first place and return the buffer as it is.
return buffer;
}
}
}
} catch (IOException e) {
throw new TransformerException(I18nMessageFactory.createStaticMessage("Failed to uncompress message."), this, e);
}
}
Aggregations