Search in sources :

Example 41 with ByteArrayOutputStream

use of org.apache.nifi.stream.io.ByteArrayOutputStream in project nifi by apache.

the class SnippetManager method export.

public byte[] export() {
    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final DataOutputStream dos = new DataOutputStream(baos)) {
        for (final StandardSnippet snippet : getSnippets()) {
            final byte[] bytes = StandardSnippetSerializer.serialize(snippet);
            dos.writeInt(bytes.length);
            dos.write(bytes);
        }
        return baos.toByteArray();
    } catch (final IOException e) {
        // won't happen
        return null;
    }
}
Also used : DataOutputStream(org.apache.nifi.stream.io.DataOutputStream) ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 42 with ByteArrayOutputStream

use of org.apache.nifi.stream.io.ByteArrayOutputStream in project nifi by apache.

the class QueryCassandraTest method testConvertToJSONStream.

@Test
public void testConvertToJSONStream() throws Exception {
    ResultSet rs = CassandraQueryTestUtil.createMockResultSet();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    long numberOfRows = QueryCassandra.convertToJsonStream(rs, baos, StandardCharsets.UTF_8, 0, null);
    assertEquals(2, numberOfRows);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 43 with ByteArrayOutputStream

use of org.apache.nifi.stream.io.ByteArrayOutputStream in project nifi by apache.

the class GenerateAttachment method SimpleEmail.

public byte[] SimpleEmail() {
    MimeMessage mimeMessage = SimpleEmailMimeMessage();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {
        mimeMessage.writeTo(output);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    }
    return output.toByteArray();
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 44 with ByteArrayOutputStream

use of org.apache.nifi.stream.io.ByteArrayOutputStream in project nifi by apache.

the class GenerateAttachment method WithAttachments.

public byte[] WithAttachments(int amount) {
    MultiPartEmail email = new MultiPartEmail();
    try {
        email.setFrom(from);
        email.addTo(to);
        email.setSubject(subject);
        email.setMsg(message);
        email.setHostName(hostName);
        int x = 1;
        while (x <= amount) {
            // Create an attachment with the pom.xml being used to compile (yay!!!)
            EmailAttachment attachment = new EmailAttachment();
            attachment.setPath("pom.xml");
            attachment.setDisposition(EmailAttachment.ATTACHMENT);
            attachment.setDescription("pom.xml");
            attachment.setName("pom.xml" + String.valueOf(x));
            // attach
            email.attach(attachment);
            x++;
        }
        email.buildMimeMessage();
    } catch (EmailException e) {
        e.printStackTrace();
    }
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    MimeMessage mimeMessage = email.getMimeMessage();
    try {
        mimeMessage.writeTo(output);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    }
    return output.toByteArray();
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) EmailAttachment(org.apache.commons.mail.EmailAttachment) EmailException(org.apache.commons.mail.EmailException) ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 45 with ByteArrayOutputStream

use of org.apache.nifi.stream.io.ByteArrayOutputStream in project nifi by apache.

the class JmsFactory method getMessageBytes.

private static byte[] getMessageBytes(StreamMessage message) throws JMSException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] byteBuffer = new byte[4096];
    int byteCount;
    while ((byteCount = message.readBytes(byteBuffer)) != -1) {
        baos.write(byteBuffer, 0, byteCount);
    }
    try {
        baos.close();
    } catch (final IOException ioe) {
    }
    return baos.toByteArray();
}
Also used : ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

ByteArrayOutputStream (org.apache.nifi.stream.io.ByteArrayOutputStream)71 Test (org.junit.Test)51 TestRunner (org.apache.nifi.util.TestRunner)27 MockFlowFile (org.apache.nifi.util.MockFlowFile)25 File (java.io.File)22 ByteArrayInputStream (org.apache.nifi.stream.io.ByteArrayInputStream)22 Schema (org.apache.avro.Schema)21 IOException (java.io.IOException)15 Peer (org.apache.nifi.remote.Peer)15 GenericDatumWriter (org.apache.avro.generic.GenericDatumWriter)14 GenericRecord (org.apache.avro.generic.GenericRecord)13 TransactionResultEntity (org.apache.nifi.web.api.entity.TransactionResultEntity)12 DataInputStream (java.io.DataInputStream)11 DataOutputStream (java.io.DataOutputStream)11 SiteToSiteRestApiClient (org.apache.nifi.remote.util.SiteToSiteRestApiClient)9 DataPacket (org.apache.nifi.remote.protocol.DataPacket)8 SiteToSiteTestUtils.createDataPacket (org.apache.nifi.remote.protocol.SiteToSiteTestUtils.createDataPacket)8 Response (org.apache.nifi.remote.protocol.Response)7 UnknownHostException (java.net.UnknownHostException)6 ApiOperation (io.swagger.annotations.ApiOperation)5