Answer a UTF-8 {@code String} from {@code body} bytes.
@param body the byte[]
@return String
336554
private static String bytesToUTF8(final byte[] body) {
    final String encoded = new String(body, Charset.forName("UTF-8"));
    return encoded;
  }
949315
public void setBody(CharSequence body) {
        String bodyString;
        if (body != null) {
            bodyString = body.toString();
        } else {
            bodyString = null;
        }
        setBody(bodyString);
    }
1160823
def utf8str(code)
      if (code & ~(0x7f)) == 0
        # UCS-4 range 0x00000000 - 0x0000007F
        return(code.chr)
      end

      buf = ""
      if (code & ~(0x7ff)) == 0
        # UCS-4 range 0x00000080 - 0x000007FF
        buf << (0b11000000 | (code >> 6)).chr
        buf << (0b10000000 | (code & 0b00111111)).chr
        return(buf)
      end

      if (code & ~(0x000ffff)) == 0
        # UCS-4 range 0x00000800 - 0x0000FFFF
        buf << (0b11100000 | (code >> 12)).chr
        buf << (0b10000000 | ((code >> 6) & 0b00111111)).chr
        buf << (0b10000000 | (code & 0b0011111)).chr
        return(buf)
      end

      # Not used -- JSON only has UCS-2, but for the sake
      # of completeness
      if (code & ~(0x1FFFFF)) == 0
        # UCS-4 range 0x00010000 - 0x001FFFFF
        buf << (0b11110000 | (code >> 18)).chr
        buf << (0b10000000 | ((code >> 12) & 0b00111111)).chr
        buf << (0b10000000 | ((code >> 6) & 0b00111111)).chr
        buf << (0b10000000 | (code & 0b0011111)).chr
        return(buf)
      end

      if (code & ~(0x03FFFFFF)) == 0
        # UCS-4 range 0x00200000 - 0x03FFFFFF
        buf << (0b11110000 | (code >> 24)).chr
        buf << (0b10000000 | ((code >> 18) & 0b00111111)).chr
        buf << (0b10000000 | ((code >> 12) & 0b00111111)).chr
        buf << (0b10000000 | ((code >> 6) & 0b00111111)).chr
        buf << (0b10000000 | (code & 0b0011111)).chr
        return(buf)
      end

      # UCS-4 range 0x04000000 - 0x7FFFFFFF
      buf << (0b11111000 | (code >> 30)).chr
      buf << (0b10000000 | ((code >> 24) & 0b00111111)).chr
      buf << (0b10000000 | ((code >> 18) & 0b00111111)).chr
      buf << (0b10000000 | ((code >> 12) & 0b00111111)).chr
      buf << (0b10000000 | ((code >> 6) & 0b00111111)).chr
      buf << (0b10000000 | (code & 0b0011111)).chr
      return(buf)
    end
958943
private static byte[] stringToBytes(String text) {
        byte[] data;
        try {
            data = text.getBytes(Charset.forName(StandardCharsets.UTF_8.name()));
        } catch (UnsupportedCharsetException ex) {
            data = text.getBytes(Charset.defaultCharset());
        }
        return data;
    }
627170
public static String bytes2String(byte[] bytes) {
    try {
      final int len = bytes.length;
      char[] charArray = UTF8.getCharArray(len);
      for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] < UTF8.MIN_ASCII_CODE) {
          // non-ASCII codepoints' higher bytes
          // are of the form (10xxxxxx), hence the bytes
          // represent a non-ASCII string
          // do expensive conversion
          return new String(bytes, utf8charsetName);
        }
        // copy to temporary array
        charArray[i] = (char) bytes[i];
      }
      // only ASCII bytes, do fast conversion
      // using bytes as actual characters
      return new String(charArray, 0, len);
    } catch (UnsupportedEncodingException e) {
      assert false : "UTF8 encoding is not supported ";
    }
    return null;
  }
304810
public static byte[] utf8Encode(CharSequence string) {
		try {
			ByteBuffer bytes = UTF8.newEncoder().encode(CharBuffer.wrap(string));
			byte[] bytesCopy = new byte[bytes.limit()];
			System.arraycopy(bytes.array(), 0, bytesCopy, 0, bytes.limit());
			return bytesCopy;
		}
		catch (CharacterCodingException e) {
			throw new RuntimeException(e);
		}
	}
968532
public static String toStringUTF8(byte[] input)
    {
        if (input == null)
        {
            return null;
        }

        try
        {
            return new String(input, "UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {
            // This won't happen.
            return null;
        }
    }
1144794
protected static function convertBodyEncoding($body, $charset = '', $encoding = -1)
    {
        if ('' === $charset) {
            $charset = static::$charset;
        }

        if (!mb_check_encoding($body, $charset)) {
            $charset = mb_detect_encoding($body);
        }

        if ($charset === static::$charset) {
            return $body;
        }

        if (!in_array($charset, mb_list_encodings())) {
            $charset = $encoding === ENC7BIT ? 'US-ASCII' : static::$charset;
        }

        return mb_convert_encoding($body, static::$charset, $charset);
    }
975387
public Response andTextBody(String text) {
        this.contentType = MediaType.PLAIN_TEXT_UTF_8.withoutParameters().toString();
        this.body = text;
        this.rendered = false;

        return this;
    }
169465
public HttpConnection setRequestBody(final String input) {
        try {
            final byte[] inputBytes = input.getBytes("UTF-8");
            return setRequestBody(inputBytes);
        } catch (UnsupportedEncodingException e) {
            // This should never happen as every implementation of the java platform is required
            // to support UTF-8.
            throw new RuntimeException(e);
        }
    }
463467
def _handle_utf8_payload(body, properties):
        
        if 'content_encoding' not in properties:
            properties['content_encoding'] = 'utf-8'
        encoding = properties['content_encoding']
        if compatibility.is_unicode(body):
            body = body.encode(encoding)
        elif compatibility.PYTHON3 and isinstance(body, str):
            body = bytes(body, encoding=encoding)
        return body
1372262
public static byte[] decode(String s) {
		byte[] bytes;
		try {
			bytes = s.getBytes(PREFERRED_ENCODING);
		} // end try
		catch (java.io.UnsupportedEncodingException uee) {
			bytes = s.getBytes();
		} // end catch

		// Decode
		bytes = decode(bytes);

		return bytes;
	}
97313
public static ByteBuffer fromUtf8String(CharSequence utfString) {
        if (utfString == null || utfString.length() == 0) {
            return Buffers.EMPTY_BYTE_BUFFER;
        } else {
            return ByteBuffer.wrap(utfString.toString().getBytes(StandardCharsets.UTF_8));
        }
    }
321867
public String getStringBody() throws UnsupportedEncodingException {
        if (mStringBody != null)
            return mStringBody;

        if (mContentType != null) {
            switch (mContentType) {
                case JSON:
                    JsonObject jsonBody = new JsonObject();
                    for (Map.Entry<String, Object> entry : mBodyMap.entrySet()) {
                        parseHashMapEntry(jsonBody, entry);
                    }
                    mStringBody = jsonBody.toString();
                    break;
                case URL_ENCODED:
                    HashMap<String, String> stringMap = new HashMap<String, String>();
                    for (Map.Entry<String, Object> entry : mBodyMap.entrySet()) {
                        stringMap.put(entry.getKey(), (String) entry.getValue());
                    }
                    mStringBody = createQuery(stringMap);
                    break;
                case JSON_PATCH:
                    mStringBody = ((BoxArray) mBodyMap.get(JSON_OBJECT)).toJson();
                    break;
            }
        }

        return mStringBody;
    }
1023804
public static Body from(final ByteBuffer body, final Encoding encoding) {
    switch (encoding) {
    case Base64:
      return new Body(bytesToBase64(bufferToArray(body)));
    case UTF8:
      return new Body(bytesToUTF8(bufferToArray(body)));
    }
    throw new IllegalArgumentException("Unmapped encoding: " + encoding);
  }
1078263
private static JsJmsMessage decodeObjectBody(String body) throws MessageDecodeFailedException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "decodeObjectBody");
        JsJmsObjectMessage result = new JsJmsObjectMessageImpl(MfpConstants.CONSTRUCTOR_NO_OP);
        if (body != null)
            result.setSerializedObject(HexString.hexToBin(body, 0));
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "decodeObjectBody");
        return result;
    }
406771
def utf8(value):
    
    """
    try:
        if isinstance(value, bytes):
            return value.decode('utf-8')
        else:
            return value
    except Exception:
        raise ValueError('Not UTF-8: %r' % value)