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


Java InputStreamCallback类代码示例

本文整理汇总了Java中org.apache.nifi.processor.io.InputStreamCallback的典型用法代码示例。如果您正苦于以下问题:Java InputStreamCallback类的具体用法?Java InputStreamCallback怎么用?Java InputStreamCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InputStreamCallback类属于org.apache.nifi.processor.io包,在下文中一共展示了InputStreamCallback类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPut

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的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: validateAndParseJSONContent

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的package包/类
Map<String, Object> validateAndParseJSONContent(ProcessSession processSession, FlowFile flowFile) throws JsonParseException {
    final Map<String, Object> jsonContent = Maps.newHashMap();

    try {
        processSession.read(flowFile, new InputStreamCallback() {
            @Override
            public void process(InputStream in) throws IOException {
                JsonParser jp = jsonFactory.createParser(in);
                jsonContent.putAll(jp.readValueAs(Map.class));
            }
        });
    } catch (ProcessException e) {
        if (e.getCause() instanceof JsonParseException) {
            throw (JsonParseException)e.getCause();
        } else {
            throw e;
        }
    }

    return jsonContent;
}
 
开发者ID:SwingDev,项目名称:nifi-file-from-template-processor,代码行数:22,代码来源:PutFileFromTemplate.java

示例3: extractMessageBody

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的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

示例4: onTrigger

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession processSession) {
    List<FlowFile> flowFiles = processSession.get(batchSize);
    if (flowFiles.isEmpty()) {
        return;
    }

    Session jschSession = null;
    Channel channel = null;
    try {
        jschSession = openSession(context);
        final String remotePath = context.getProperty(REMOTE_PATH).evaluateAttributeExpressions().getValue();
        channel = openExecChannel(context, jschSession, "scp -r -d -t " + remotePath);

        InputStream channelIn = channel.getInputStream();
        OutputStream channelOut = channel.getOutputStream();

        channel.connect();
        waitForAck(channelIn);

        ListIterator<FlowFile> fileIt = flowFiles.listIterator();
        while (fileIt.hasNext()) {
            final FlowFile flowFile = fileIt.next();

            // conditionally reject files that are zero bytes or less
            if (context.getProperty(REJECT_ZERO_BYTE).asBoolean() && flowFile.getSize() == 0) {
                logger.warn("Rejecting {} because it is zero bytes", new Object[]{flowFile});
                processSession.transfer(processSession.penalize(flowFile), REL_REJECT);
                fileIt.remove();
                continue;
            }

            final String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key());
            final String permissions = context.getProperty(PERMISSIONS).evaluateAttributeExpressions(flowFile).getValue();

            // destination path + filename
            // final String fullPath = buildFullPath(context, flowFile, filename);

            processSession.read(flowFile, new InputStreamCallback() {
                @Override
                public void process(final InputStream flowFileIn) throws IOException {
                    // send "C0644 filesize filename", where filename should not include '/'
                    StringBuilder command = new StringBuilder("C").append(permissions).append(' ');
                    command.append(flowFile.getSize()).append(' ');
                    command.append(filename).append('\n');

                    channelOut.write(command.toString().getBytes(StandardCharsets.UTF_8));
                    channelOut.flush();
                    waitForAck(channelIn);

                    IOUtils.copy(flowFileIn, channelOut);
                    channelOut.flush();
                    sendAck(channelOut);
                    waitForAck(channelIn);
                }
            });

            processSession.transfer(flowFile, REL_SUCCESS);
            processSession.getProvenanceReporter().send(flowFile, remotePath);
            fileIt.remove();
            if (logger.isDebugEnabled()) {
                logger.debug("Sent {} to remote host", new Object[]{flowFile});
            }
        }

    } catch (JSchException | IOException ex) {
        context.yield();
        logger.error("Unable to create session to remote host due to {}", new Object[]{ex}, ex);
        processSession.transfer(flowFiles, REL_FAILURE);

    } finally {
        if (channel != null) {
            channel.disconnect();
        }
        if (jschSession != null) {
            jschSession.disconnect();
        }
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:80,代码来源:PutScp.java

示例5: onTrigger

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    FlowFile flowfile = session.get();

    final String regex = context.getProperty(REGEX).getValue();
    final Boolean regexGroupSupport = Boolean.parseBoolean(context.getProperty(REGEX_GROUP_SUPPORT).getValue());
    final Integer occurrence = Integer.parseInt(context.getProperty(OCCURRENCE).getValue());

    final AtomicReference<String> partValue = new AtomicReference<String>();

    final FilePartByRegEx fp = new FilePartByRegEx();
    fp.setOccurrence(occurrence);
    fp.setRegexGroupSupport(regexGroupSupport);
    fp.setRegex(regex);

    if (flowfile == null) {
        return;
    }

    session.read(flowfile, new InputStreamCallback() {
        @Override
        public void process(InputStream in) throws IOException {
            try {
                fp.setInputStream(in);

                partValue.set(fp.getValue());

            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    flowfile = session.putAttribute(flowfile, "file.part.value", partValue.get());

    session.transfer(flowfile, SUCCESS);

}
 
开发者ID:dstreev,项目名称:nifi-processor-examples,代码行数:39,代码来源:FilePartByRegExProcessor.java

示例6: onTrigger

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {

	final AtomicReference<String[]> value = new AtomicReference<String[]>();
	final AtomicReference<String> result =new AtomicReference<String>();
	HashMap<String, String> map = new HashMap<String, String>(); 
       FlowFile flowfile = session.get();
       openFile(context.getProperty(EXPERIMENT_LOG_FILE).getValue());
       expLogStream.println(String.format("%s,%s,%s,%s", flowfile.getAttribute(ExperimentAttributes.FLOWFILE_ID.key()),
               SenMLParser.class, (new Timestamp(System.currentTimeMillis())).getTime(), "ENTRY"));

       session.read(flowfile, new InputStreamCallback() {
           @Override
           public void process(InputStream in)  {
               try{
               	String json = IOUtils.toString(in, "UTF-8");
               	String[] obsType = json.split(System.getProperty("line.separator"));
               	value.set(obsType);
                                       
               }catch(Exception ex){
                   ex.printStackTrace();
                   getLogger().error("Failed to read json string.");
                   getLogger().error(ex.toString());
               }
           }
       });
       String partResult = "";
	for(String msg:value.get()) {
          Map<String, String> parsedMap =  getResult(msg.split(",",2)[1]);
          partResult += parsedMap.toString()+"\n";           
	}
	partResult.trim();
       result.set(partResult);
       // To write the results back out to flow file
    flowfile = session.write(flowfile, new OutputStreamCallback() {
    
    	public void process(OutputStream out) throws IOException {
        	out.write(result.toString().getBytes());
    		//out.write(value.get().getBytes());
        }
		
    });
       expLogStream.println(String.format("%s,%s,%s,%s", flowfile.getAttribute(ExperimentAttributes.FLOWFILE_ID.key()),
               ETLGetFile.class, (new Timestamp(System.currentTimeMillis())).getTime(), "EXIT"));
       expLogStream.flush();

    session.transfer(flowfile,REL_SUCCESS);
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:49,代码来源:SenMLParser.java

示例7: onTrigger

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
	
	final ComponentLog logger = getLogger();
	
	// Initialize  response variable
    final AtomicReference<String> requestedTagname = new AtomicReference<>();
    
    
    
    // get FlowFile
    FlowFile flowFile = session.get();
    if ( flowFile == null ) {
        return;
    }
    // Read tag name from flow file content
    session.read(flowFile, new InputStreamCallback() {
        @Override
        public void process(InputStream in) throws IOException {
        	
            try{
            	String tagname = new BufferedReader(new InputStreamReader(in))
            	  .lines().collect(Collectors.joining("\n"));

                requestedTagname.set(tagname);
                
            }catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
        }
        
    });
    
    // Submit to getValue
    final OPCUAService opcUAService = context.getProperty(OPCUA_SERVICE)
    		.asControllerService(OPCUAService.class);
   
    if(opcUAService.updateSession()){
    	logger.debug("Session current");
    }else {
    	logger.debug("Session update failed");
    }
    
// Write the results back out to flow file
    flowFile = session.write(flowFile, new OutputStreamCallback() {

        @Override
        public void process(OutputStream out) throws IOException {
        	out.write(opcUAService.getValue(requestedTagname.get()));
        	
        }
        
    });
    
    session.transfer(flowFile, SUCCESS);
    
}
 
开发者ID:wadesalazar,项目名称:NIFI-OPCUA,代码行数:60,代码来源:GetValue.java

示例8: onTrigger

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
	FlowFile flowFile = session.get();
	if (flowFile == null) {
		flowFile = session.create();
	}
	try {
		flowFile.getAttributes();

		// read all bytes of the flowfile (tensor requires whole image)
		String modelDir = flowFile.getAttribute(MODEL_DIR_NAME);
		if (modelDir == null) {
			modelDir = context.getProperty(MODEL_DIR_NAME).evaluateAttributeExpressions(flowFile).getValue();
		}
		if (modelDir == null) {
			modelDir = "/models";
		}
		final String model = modelDir;

		try {
			final HashMap<String, String> attributes = new HashMap<String, String>();

			session.read(flowFile, new InputStreamCallback() {
				@Override
				public void process(InputStream input) throws IOException {
					byte[] byteArray = IOUtils.toByteArray(input);
					getLogger().info(
							String.format("read %d bytes from incoming file", new Object[] { byteArray.length }));
					List<Entry<Float, String>> results = service.getInception(byteArray, model);
					getLogger().debug(String.format("Found %d results", new Object[] { results.size() }));
					for (int i = 0; i < results.size(); i++) {
						Object[] key = new Object[] { ATTRIBUTE_OUTPUT_NAME, i };
						Entry<Float, String> entry = results.get(i);
						attributes.put(String.format("%s.%d.label", key), entry.getValue());
						attributes.put(String.format("%s.%d.probability", key), entry.getKey().toString());
					}

				}
			});
			if (attributes.size() == 0) {
				session.transfer(flowFile, REL_FAILURE);
			} else {
				flowFile = session.putAllAttributes(flowFile, attributes);
				session.transfer(flowFile, REL_SUCCESS);
			}
		} catch (Exception e) {
			throw new ProcessException(e);
		}

		session.commit();
	} catch (

	final Throwable t) {
		getLogger().error("Unable to process TensorFlow Processor file " + t.getLocalizedMessage());
		throw new ProcessException(t);
	}
}
 
开发者ID:tspannhw,项目名称:nifi-tensorflow-processor,代码行数:58,代码来源:TensorFlowProcessor.java

示例9: onTrigger

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的package包/类
@Override
    public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
        FlowFile flowfile = session.get();

        final String regex = context.getProperty(REGEX).getValue();
        final Boolean hasHeader = Boolean.parseBoolean(context.getProperty(HAS_HEADER).getValue());

//        final AtomicReference<String> partValue = new AtomicReference<String>();

        final RecordLayoutValidator fp = new RecordLayoutValidator();
        fp.setExpectedRecordFormatRegEx(regex);
        fp.setHasHeader(hasHeader);

        if (flowfile == null) {
            return;
        }

        session.read(flowfile, new InputStreamCallback() {
            @Override
            public void process(InputStream in) throws IOException {
                try {

                    fp.setInputStream(in);
                    fp.validate();

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });

        boolean valid = fp.isValid();
        if (valid) {
            flowfile = session.putAttribute(flowfile, "record.count", Long.toString(fp.getRecordCount()));
            session.transfer(flowfile, SUCCESS);
        } else {
            session.transfer(flowfile, FAILURE);

            // To write the results back out ot flow file
            flowfile = session.write(flowfile, new OutputStreamCallback() {

                @Override
                public void process(OutputStream out) throws IOException {
                    Map<Long, String> errorMap = fp.getErrors();
                    Set<Long> keys = errorMap.keySet();

                    for (Long key: keys) {
                        String badLine = errorMap.get(key);
                        StringBuilder sb = new StringBuilder();
                        sb.append(key);
                        sb.append("\t");
                        sb.append(badLine);
                        out.write(sb.toString().getBytes());
                    }
                }
            });

            session.transfer(flowfile, ERRORS);

        }


    }
 
开发者ID:dstreev,项目名称:nifi-processor-examples,代码行数:64,代码来源:RecordLayoutValidatorProcessor.java

示例10: onTrigger

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的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

示例11: onTrigger

import org.apache.nifi.processor.io.InputStreamCallback; //导入依赖的package包/类
/**
 *
 */
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
	final ProcessorLog log = this.getLogger();
	long executionCompletionTimeout = Long.parseLong(context.getProperty(EXECUTION_COMPLETION_TIMEOUT).getValue());

	FlowFile flowFile = session.get();
	if (flowFile != null){
		try {
			String configurationName = flowFile.getAttribute("filename");
			Assert.isTrue(configurationName.endsWith(".cfg"), "Received invalid configuration file '" +
					configurationName + "'. DStream configuration file must end with '.cfg'.");

			log.info("Recieved configuration '" + configurationName + "'");
			AtomicReference<String> outputPathRef = new AtomicReference<String>();
			session.read(flowFile, new InputStreamCallback() {
				@Override
				public void process(InputStream confFileInputStream) throws IOException {
					outputPathRef.set(installConfiguration(configurationName, confFileInputStream));
				}
			});
			String executionName = configurationName.split("\\.")[0];

			DStream<?> dstream = this.getDStream(executionName);
			if (dstream != null){
				log.info("Executing DStream for '" + executionName + "'");
				this.postProcessResults(this.executeDStream(dstream, executionName, executionCompletionTimeout));
				FlowFile resultFlowFile = session.create();
				resultFlowFile = session.putAttribute(resultFlowFile, CoreAttributes.FILENAME.key(), outputPathRef.get());
				session.getProvenanceReporter().receive(resultFlowFile, outputPathRef.get());
				session.transfer(resultFlowFile, OUTPUT);
			} else {
				log.warn("Failed to locate DStream for execution '" + executionName + "'"
						+ ". Nothing was executed. Possible reasons: " + this.getClass().getSimpleName()
						+ " may not have provided a DStream for '" + executionName + "'");
			}
		}
		catch (Exception e) {
			throw new IllegalStateException("Failed DStream execution with unexpected exception ", e);
		}
		finally {
			session.remove(flowFile);
			session.commit();
		}
	}
}
 
开发者ID:hortonworks,项目名称:dstream,代码行数:49,代码来源:AbstractDStreamProcessor.java


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