This is a Hashing processor where I want to hash a FileInputStream using the SHA-1 algorithm and then add the hash to the exchange header under "HashValue"
@Component
public class FileContentHashExpression implements Expression {
@Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
// TODO Check for String type and generic file message
if (type != String.class){
throw new IllegalArgumentException("This is String only expression");
}
try (FileInputStream fileInputStream = new FileInputStream(((File)exchange.getIn(GenericFileMessage.class).getGenericFile().getFile()))) {
exchange.getIn().setHeader("HashValue", DigestUtils.sha1(fileInputStream));
return (T) (DigestUtils.sha1(fileInputStream));
} catch (IOException e) {
throw new RuntimeException(e);
}
}