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;
}
}
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);
}
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();
}
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();
}
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();
}
Aggregations