@Override public void encode(final DataPacket dataPacket, final OutputStream encodedOut) throws IOException { final DataOutputStream out = new DataOutputStream(encodedOut); final Map<String, String> attributes = dataPacket.getAttributes(); out.writeInt(attributes.size()); for (final Map.Entry<String, String> entry : attributes.entrySet()) { writeString(entry.getKey(), out); writeString(entry.getValue(), out); } out.writeLong(dataPacket.getSize()); final InputStream in = dataPacket.getData(); StreamUtils.copy(in, encodedOut); encodedOut.flush(); }
public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); } }
private void verifyTransactions(List<String> expectedContents, List<MockTransaction> transactions) throws IOException { // convert all the data packets in the transactions to strings final List<String> dataPacketContents = new ArrayList<>(); for (MockTransaction mockTransaction : transactions) { List<DataPacket> dps = mockTransaction.getSentDataPackets(); Assert.assertTrue(dps.size() > 0); for (DataPacket dp : dps) { final String dpContent = IOUtils.toString(dp.getData()); dataPacketContents.add(dpContent); } } // verify each expected piece of content is found in the data packet contents for (String expectedContent : expectedContents) { boolean found = false; for (String dataPacket : dataPacketContents) { if (dataPacket.equals(expectedContent)) { found = true; break; } } Assert.assertTrue(found); } }
contentBytes += dataPacket.getSize(); this.state = TransactionState.DATA_EXCHANGED; } catch (final IOException ioe) {
flowFile = session.importFrom(dataPacket.getData(), flowFile); flowFile = session.putAllAttributes(flowFile, dataPacket.getAttributes()); final String sourceSystemFlowFileUuid = dataPacket.getAttributes().get(CoreAttributes.UUID.key());
} else { transfers++; contentBytes += packet.getSize();
final InputStream inStream = dataPacket.getData(); final byte[] data = new byte[(int) dataPacket.getSize()]; StreamUtils.fillBuffer(inStream, data); final Map<String, String> attributes = dataPacket.getAttributes();
public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); } }
final InputStream inStream = dataPacket.getData(); final byte[] data = new byte[(int) dataPacket.getSize()]; StreamUtils.fillBuffer(inStream, data); final Map<String, String> attributes = dataPacket.getAttributes(); final NiFiDataPacket niFiDataPacket = new StandardNiFiDataPacket(data, attributes);
flowFile = session.importFrom(dataPacket.getData(), flowFile); flowFile = session.putAllAttributes(flowFile, dataPacket.getAttributes()); final String sourceSystemFlowFileUuid = dataPacket.getAttributes().get(CoreAttributes.UUID.key());
flowFile = session.putAllAttributes(flowFile, dataPacket.getAttributes()); flowFile = session.importFrom(dataPacket.getData(), flowFile); final long receiveNanos = System.nanoTime() - start; flowFilesReceived.add(flowFile); String sourceFlowFileIdentifier = dataPacket.getAttributes().get(CoreAttributes.UUID.key()); if (sourceFlowFileIdentifier == null) { sourceFlowFileIdentifier = "<Unknown Identifier>"; bytesReceived += dataPacket.getSize();
final InputStream inStream = dataPacket.getData(); final byte[] data = new byte[(int) dataPacket.getSize()]; StreamUtils.fillBuffer(inStream, data); final Map<String, String> attributes = dataPacket.getAttributes(); final NiFiDataPacket NiFiDataPacket = new StandardNiFiDataPacket(data, attributes); dataPackets.add(NiFiDataPacket);
@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); }
@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); }
flowFile = session.putAllAttributes(flowFile, dataPacket.getAttributes()); flowFile = session.importFrom(dataPacket.getData(), flowFile); final long receiveNanos = System.nanoTime() - start; flowFilesReceived.add(flowFile); String sourceFlowFileIdentifier = dataPacket.getAttributes().get(CoreAttributes.UUID.key()); if (sourceFlowFileIdentifier == null) { sourceFlowFileIdentifier = "<Unknown Identifier>"; bytesReceived += dataPacket.getSize();