@Test public void testMsg() { String boundary = "----=_Part_4_910054940.1065629194743"; final byte[] chunk1 = concat(("--" + boundary + "\n" + "Content-Type: text/xml; charset=UTF-8\n" + "Content-Transfer-Encoding: binary\n" + "Content-Id: part1\n" + "Content-Description: this is part1\n" + "\n" + "<foo>bar</foo>\n" + "--" + boundary + "\n" + "Content-Type: image/jpeg\n" + "Content-Transfer-Encoding: binary\n" + "Content-Id: part2\n" + "\n").getBytes(), new byte[]{(byte) 0xff, (byte) 0xd8}, ("\n--" + boundary + "--").getBytes()); List<MimePart> parts = parse(boundary, chunk1).parts; assertThat(parts.size(), is(equalTo(2))); MimePart part1 = parts.get(0); assertThat(part1.headers.get("Content-Type"), hasItems("text/xml; charset=UTF-8")); assertThat(part1.headers.get("Content-Transfer-Encoding"), hasItems("binary")); assertThat(part1.headers.get("Content-Id"), hasItems("part1")); assertThat(part1.headers.get("Content-Description"), hasItems("this is part1")); assertThat(part1.content, is(notNullValue())); assertThat(new String(part1.content), is(equalTo("<foo>bar</foo>"))); MimePart part2 = parts.get(1); assertThat(part2.headers.get("Content-Type"), hasItems("image/jpeg")); assertThat(part2.headers.get("Content-Transfer-Encoding"), hasItems("binary")); assertThat(part2.headers.get("Content-Id"), hasItems("part2")); assertThat(part2.content, is(notNullValue())); assertThat(part2.content[0], is(equalTo((byte) 0xff))); assertThat(part2.content[1], is(equalTo((byte) 0xd8))); }
private static byte[] getBytes(String str) { char[] chars = str.toCharArray(); int size = chars.length; byte[] bytes = new byte[size]; for (int i = 0; i < size;) { bytes[i] = (byte) chars[i++]; } return bytes; }
MimeParser { private static byte[] getBytes(String str) { char[] chars = str.toCharArray(); int size = chars.length; byte[] bytes = new byte[size]; for (int i = 0; i < size;) { bytes[i] = (byte) chars[i++]; } return bytes; } }
MimeParser { private static byte[] getBytes(String str) { char[] chars = str.toCharArray(); int size = chars.length; byte[] bytes = new byte[size]; for (int i = 0; i < size;) { bytes[i] = (byte) chars[i++]; } return bytes; } MimeParser(String boundary); }
MimeParser { private static byte[] getBytes(String str) { char[] chars = str.toCharArray(); int size = chars.length; byte[] bytes = new byte[size]; for (int i = 0; i < size;) { bytes[i] = (byte) chars[i++]; } return bytes; } MimeParser(String boundary);  }
MimeParser { private static byte[] getBytes(String str) { char[] chars = str.toCharArray(); int size = chars.length; byte[] bytes = new byte[size]; for (int i = 0; i < size;) { bytes[i] = (byte) chars[i++]; } return bytes; } MimeParser(String boundary);   }