@Test public void asBytesShouldSerializeTheMessage() throws Exception { byte[] bytes = DefaultMessageWriter.asBytes( Message.Builder.of() .setBody("this is the body", Charsets.UTF_8) .setFrom("sender@localhost") .setTo("receiver@localhost") .setSubject("Cool subject") .build()); assertThat(new String(bytes, Charsets.UTF_8.name())) .isEqualTo("MIME-Version: 1.0\r\n" + "Content-Type: text/plain; charset=UTF-8\r\n" + "From: sender@localhost\r\n" + "To: receiver@localhost\r\n" + "Subject: Cool subject\r\n" + "\r\n" + "this is the body"); }
public static byte[] asBytes(Message message) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DefaultMessageWriter writer = new DefaultMessageWriter(); writer.writeMessage(message, buffer); return buffer.toByteArray(); }
DefaultMessageWriter implements MessageWriter { public static byte[] asBytes(Message message) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DefaultMessageWriter writer = new DefaultMessageWriter(); writer.writeMessage(message, buffer); return buffer.toByteArray(); } }
DefaultMessageWriter implements MessageWriter { public static byte[] asBytes(Message message) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DefaultMessageWriter writer = new DefaultMessageWriter(); writer.writeMessage(message, buffer); return buffer.toByteArray(); } DefaultMessageWriter(); }
DefaultMessageWriter implements MessageWriter { public static byte[] asBytes(Message message) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DefaultMessageWriter writer = new DefaultMessageWriter(); writer.writeMessage(message, buffer); return buffer.toByteArray(); } DefaultMessageWriter(); static byte[] asBytes(Message message); void writeBody(Body body, OutputStream out); void writeEntity(Entity entity, OutputStream out); void writeMessage(Message message, OutputStream out); void writeMultipart(Multipart multipart, OutputStream out); void writeField(Field field, OutputStream out); void writeHeader(Header header, OutputStream out); }
DefaultMessageWriter implements MessageWriter { public static byte[] asBytes(Message message) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DefaultMessageWriter writer = new DefaultMessageWriter(); writer.writeMessage(message, buffer); return buffer.toByteArray(); } DefaultMessageWriter(); static byte[] asBytes(Message message); void writeBody(Body body, OutputStream out); void writeEntity(Entity entity, OutputStream out); void writeMessage(Message message, OutputStream out); void writeMultipart(Multipart multipart, OutputStream out); void writeField(Field field, OutputStream out); void writeHeader(Header header, OutputStream out);  }