Here you can find the source of getAsByteBuffer()
public static ByteBuffer getAsByteBuffer()
//package com.java2s; /*//from w ww . ja va2s. c om * Copyright (c) xsocket.org, 2006 - 2009. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt * The latest copy of this software may be found on http://www.xsocket.org/ */ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; public class Main { private static String testMail = "Received: from localhost (localhost [127.0.0.1])\r\n" + "by Semta.de with ESMTP id 881588961.1153334034540.1900236652.1\r\n" + "for feki@semta.de; Mi, 19 Jul 2006 20:34:00 +0200\r\n" + "Message-ID: <24807938.01153334039898.JavaMail.grro@127.0.0.1>\r\n" + "Date: Wed, 19 Jul 2006 20:33:59 +0200 (CEST)\r\n" + "From: feki2 <fekete99@web.de>\r\n" + "To: Gregor Roth <feki@semta.de>\r\n" + "Subject: Test mail\r\n" + "MIME-Version: 1.0\r\n" + "Content-Type: multipart/mixed;\r\n" + "boundary=\"----=_Part_1_14867177.1153334039707\"\r\n" + "\r\n" + "This is a multi-part message in MIME format.\r\n" + "------=_Part_1_14867177.1153334039707\r\n" + "Content-Type: multipart/mixed;\r\n" + "boundary=\"----=_Part_0_14158819.1153334039687\"\r\n" + "\r\n" + "------=_Part_0_14158819.1153334039687\r\n" + "Content-Type: text/plain; charset=us-ascii\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "Halli Hallo\r\n" + "------=_Part_0_14158819.1153334039687\r\n" + "------=_Part_1_14867177.1153334039707--"; public static ByteBuffer getAsByteBuffer() { try { Charset charset = Charset.forName("ISO-8859-1"); CharsetEncoder encoder = charset.newEncoder(); ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail .toCharArray())); return buf; } catch (Exception e) { throw new RuntimeException(e.toString()); } } }