本文整理汇总了Java中org.apache.nifi.stream.io.StreamUtils类的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils类的具体用法?Java StreamUtils怎么用?Java StreamUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamUtils类属于org.apache.nifi.stream.io包,在下文中一共展示了StreamUtils类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPut
import org.apache.nifi.stream.io.StreamUtils; //导入依赖的package包/类
@Override
protected PutFlowFile createPut(final ProcessSession session, final ProcessContext context, final FlowFile flowFile) {
final String tableName = context.getProperty(TABLE_NAME).evaluateAttributeExpressions(flowFile).getValue();
final String row = context.getProperty(ROW_ID).evaluateAttributeExpressions(flowFile).getValue();
final String columnFamily = context.getProperty(COLUMN_FAMILY).evaluateAttributeExpressions(flowFile).getValue();
final String columnQualifier = context.getProperty(COLUMN_QUALIFIER).evaluateAttributeExpressions(flowFile).getValue();
final String columnVisibility = context.getProperty(COLUMN_VISIBILITY).evaluateAttributeExpressions(flowFile).getValue();
final byte[] buffer = new byte[(int) flowFile.getSize()];
session.read(flowFile, new InputStreamCallback() {
@Override
public void process(final InputStream in) throws IOException {
StreamUtils.fillBuffer(in, buffer);
}
});
final Collection<PutMutation> mutations = Collections.singletonList(new PutMutation(columnFamily, columnQualifier, columnVisibility, buffer.toString()));
return new PutFlowFile(tableName, row, mutations, flowFile);
}
示例2: extractMessageBody
import org.apache.nifi.stream.io.StreamUtils; //导入依赖的package包/类
/**
* Extracts contents of the {@link FlowFile} as byte array.
*/
private byte[] extractMessageBody(FlowFile flowFile, ProcessSession session) {
final byte[] messageContent = new byte[(int) flowFile.getSize()];
session.read(flowFile, new InputStreamCallback() {
@Override
public void process(final InputStream in) throws IOException {
StreamUtils.fillBuffer(in, messageContent, true);
}
});
return messageContent;
}
示例3: onTrigger
import org.apache.nifi.stream.io.StreamUtils; //导入依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
FlowFile flowFile = session.get();
if (flowFile == null) {
return;
}
final byte[] buffer = new byte[(int) flowFile.getSize()];
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer)) {
session.read(flowFile, in -> StreamUtils.fillBuffer(in, buffer));
try (ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream)) {
// Check the first entry.
ZipEntry zipEntry = zipInputStream.getNextEntry();
String name = "";
if (zipEntry != null) {
name = zipEntry.getName();
}
flowFile = session.putAttribute(flowFile, ATTR, name);
session.getProvenanceReporter().modifyAttributes(flowFile);
session.transfer(flowFile, REL_SUCCESS);
}
} catch (Exception e) {
getLogger().error("Unable to update flowFile {} due to {}", new Object[]{flowFile, e.getMessage()}, e);
session.transfer(flowFile, REL_FAILURE);
}
}
示例4: createTuple
import org.apache.nifi.stream.io.StreamUtils; //导入依赖的package包/类
@Override
protected NiFiDataPacket createTuple(final DataPacket dataPacket) throws IOException
{
// read the data into a byte array and wrap it with the attributes into a NiFiDataPacket
final InputStream inStream = dataPacket.getData();
final byte[] data = new byte[(int)dataPacket.getSize()];
StreamUtils.fillBuffer(inStream, data);
final Map<String, String> attributes = dataPacket.getAttributes();
return new StandardNiFiDataPacket(data, attributes);
}
示例5: onTrigger
import org.apache.nifi.stream.io.StreamUtils; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
FlowFile flowFile = session.get();
if ( flowFile == null ) {
return;
}
final String outboundAddress = context.getProperty(OUTBOUND_ADDRESS).evaluateAttributeExpressions(flowFile).getValue();
try {
final StopWatch stopWatch = new StopWatch(true);
final byte[] buffer = new byte[(int) flowFile.getSize()];
session.read(flowFile, new InputStreamCallback() {
@Override
public void process(final InputStream in) throws IOException {
StreamUtils.fillBuffer(in, buffer, false);
}
});
// TODO detect flowFile MIME_TYPE and convert buffer into JSON, String or buffer
JsonObject message = new JsonObject(new String(buffer, StandardCharsets.UTF_8));
if(attributePattern != null) {
DeliveryOptions options = new DeliveryOptions();
for(String attributeName : flowFile.getAttributes().keySet()) {
if (attributePattern != null && attributePattern.matcher(attributeName).matches()) {
options.addHeader(attributeName, flowFile.getAttribute(attributeName));
}
}
put(outboundAddress, message, options);
} else {
put(outboundAddress, message);
}
final Map<String, String> attributes = new HashMap<>();
attributes.put("eventbus.address", outboundAddress);
flowFile = session.putAllAttributes(flowFile, attributes);
session.getProvenanceReporter().receive(flowFile, outboundAddress, "sent message to eventBus", stopWatch.getElapsed(TimeUnit.MILLISECONDS));
getLogger().info("Successfully sent {} ({}) to EventBuss in {} millis", new Object[]{flowFile, flowFile.getSize(), stopWatch.getElapsed(TimeUnit.MILLISECONDS)});
session.transfer(flowFile, REL_SUCCESS);
} catch (ProcessException pe) {
getLogger().error("Failed to send {} to EventBuss due to {}; routing to failure", new Object[] {flowFile, pe.toString()}, pe);
session.transfer(flowFile, REL_FAILURE);
}
}