Here you can find the source of Utf8Encode(String string)
static private String Utf8Encode(String string)
//package com.java2s; /******************************************************************************* * Copyright 2012 Gregory McFall//from w w w .j av a 2s . c o m * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ public class Main { static private String Utf8Encode(String string) { string = string.replace("\\r\\n", "\n"); String utftext = ""; for (int n = 0; n < string.length(); n++) { char c = string.charAt(n); if (c < 128) { utftext += c; } else if ((c > 127) && (c < 2048)) { utftext += ((c >> 6) | 192); utftext += ((c & 63) | 128); } else { utftext += ((c >> 12) | 224); utftext += (((c >> 6) & 63) | 128); utftext += ((c & 63) | 128); } } return utftext; } }