Java UTF8 Encode utf8FromString(String sIn)

Here you can find the source of utf8FromString(String sIn)

Description

Converts a String to a block of utf8 bytes

License

Open Source License

Declaration

public static byte[] utf8FromString(String sIn) 

Method Source Code

//package com.java2s;
/** ***************************************************************
Util.java//from   w ww  .  j  a  v a2  s .  co m
Copyright (C) 2001  Brendon Upson 
http://www.wnc.net.au info@wnc.net.au
    
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
    
This program 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 General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    
 *************************************************************** */

public class Main {
    /**
     * Converts a String to a block of utf8 bytes
     */
    public static byte[] utf8FromString(String sIn) {
        //see http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html
        final String DEFAULT_CHARSET = "UTF-8";
        byte bufReturn[] = null;
        try {
            bufReturn = sIn.getBytes(DEFAULT_CHARSET);
        } catch (Exception e) {
        }
        return bufReturn;
    }
}

Related

  1. utf8Encode(String s)
  2. utf8Encode(String str)
  3. utf8Encode(String str)
  4. Utf8Encode(String string)
  5. utf8Encode(String url)
  6. utf8urlencode(String text)