Java UTF8 Encode utf8Encode(final String value)

Here you can find the source of utf8Encode(final String value)

Description

This will convert the supplied value to a UTF-8 encoded byte array.

License

Open Source License

Parameter

Parameter Description
value to UTF-8 encode

Return

UTF-8 encoded value

Declaration

public static byte[] utf8Encode(final String value) 

Method Source Code

//package com.java2s;
/*// ww  w  .j a v  a 2  s  .com
  $Id$
    
  Copyright (C) 2003-2012 Virginia Tech.
  All rights reserved.
    
  SEE LICENSE FOR MORE INFORMATION
    
  Author:  Middleware Services
  Email:   middleware@vt.edu
  Version: $Revision$
  Updated: $Date$
*/

import java.nio.charset.Charset;

public class Main {
    /** UTF-8 character set. */
    private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");

    /**
     * This will convert the supplied value to a UTF-8 encoded byte array. Returns
     * null if the string cannot be encoded.
     *
     * @param  value  to UTF-8 encode
     *
     * @return  UTF-8 encoded value
     */
    public static byte[] utf8Encode(final String value) {
        return value != null ? value.getBytes(UTF8_CHARSET) : null;
    }
}

Related

  1. toUTF8String(byte[] b, int offset, int length)
  2. utf8Code(String str)
  3. Utf8codeCheck(String text)
  4. utf8Encode(final Collection col)
  5. utf8Encode(final String s)
  6. utf8Encode(String s)
  7. utf8Encode(String str)
  8. utf8Encode(String str)
  9. Utf8Encode(String string)