当前位置: 首页>>代码示例>>Java>>正文


Java StreamUtils类代码示例

本文整理汇总了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);
}
 
开发者ID:pinkdevelops,项目名称:nifi-accumulo-bundle,代码行数:20,代码来源:PutAccumuloCell.java

示例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;
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:14,代码来源:PublishJMS.java

示例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);
    }

}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:31,代码来源:InspectZipContents.java

示例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);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:12,代码来源:NiFiSinglePortInputOperator.java

示例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);
    }
}
 
开发者ID:xmlking,项目名称:nifi-websocket,代码行数:48,代码来源:PublishEventBus.java


注:本文中的org.apache.nifi.stream.io.StreamUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。