标签:
import org.apache.commons.io.IOUtils
import java.nio.charset.*
import java.text.SimpleDateFormat;
import java.lang.StringBuilder;
import java.util.Calendar;
def flowFile = session.create()
flowFile = session.write(flowFile, {inputStream, outputStream ->
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
StringBuilder sb = new StringBuilder();
for(int i = 0; i < 9500; i++) {
cal.add(Calendar.DATE, -1);
sb.append(sdf.format(cal.getTime()) + "\n" );
}
//println(sb);
outputStream.write(sb.toString().getBytes(StandardCharsets.UTF_8))
} as StreamCallback)
//flowFile = session.putAttribute(flowFile, ‘filename‘, ‘get_date‘)
session.transfer(flowFile, REL_SUCCESS)
Line Split Count 1
这里一定要设置filename,不然,所有的文件名都一样,最后只能成功插入一个记录到HDFS。
注意这里的Directory 要加上/, 不然就插入到user/root/nifi下了,而不是files下在的nifi了。
标签:
原文地址:http://www.cnblogs.com/fengwenit/p/5589397.html