NIFI-4405 Adding charset property to GenerateFlowFile

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #2168.
This commit is contained in:
Bryan Bende 2017-09-21 10:57:03 -04:00 committed by Pierre Villard
parent a813ae113e
commit 329dbe3a64

View File

@ -18,6 +18,7 @@ package org.apache.nifi.processors.standard;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -104,6 +105,14 @@ public class GenerateFlowFile extends AbstractProcessor {
.expressionLanguageSupported(true) .expressionLanguageSupported(true)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build(); .build();
public static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
.name("character-set")
.displayName("Character Set")
.description("Specifies the character set to use when writing the bytes of Custom Text to a flow file.")
.required(true)
.defaultValue("UTF-8")
.addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
.build();
public static final Relationship SUCCESS = new Relationship.Builder() public static final Relationship SUCCESS = new Relationship.Builder()
.name("success") .name("success")
@ -122,6 +131,7 @@ public class GenerateFlowFile extends AbstractProcessor {
descriptors.add(DATA_FORMAT); descriptors.add(DATA_FORMAT);
descriptors.add(UNIQUE_FLOWFILES); descriptors.add(UNIQUE_FLOWFILES);
descriptors.add(CUSTOM_TEXT); descriptors.add(CUSTOM_TEXT);
descriptors.add(CHARSET);
this.descriptors = Collections.unmodifiableList(descriptors); this.descriptors = Collections.unmodifiableList(descriptors);
final Set<Relationship> relationships = new HashSet<>(); final Set<Relationship> relationships = new HashSet<>();
@ -198,7 +208,8 @@ public class GenerateFlowFile extends AbstractProcessor {
if (context.getProperty(UNIQUE_FLOWFILES).asBoolean()) { if (context.getProperty(UNIQUE_FLOWFILES).asBoolean()) {
data = generateData(context); data = generateData(context);
} else if(context.getProperty(CUSTOM_TEXT).isSet()) { } else if(context.getProperty(CUSTOM_TEXT).isSet()) {
data = context.getProperty(CUSTOM_TEXT).evaluateAttributeExpressions().getValue().getBytes(); final Charset charset = Charset.forName(context.getProperty(CHARSET).getValue());
data = context.getProperty(CUSTOM_TEXT).evaluateAttributeExpressions().getValue().getBytes(charset);
} else { } else {
data = this.data.get(); data = this.data.get();
} }