如何在Google App引擎的日志中显示UTF-8字符?

时间:2016-05-20 22:36:11

标签: java google-app-engine

我目前正在使用Java,我使用System.out.println(myString)打印我的字符串;

然而,当我在谷歌应用引擎仪表板上查看我的服务器日志时,我看到一堆问号(???)代替特殊字符(在我的特定情况下,表情符号)的位置。

该字符串直接从请求的有效负载中获取。

请求的有效负载读作:

 StringBuilder stringBuilder = new StringBuilder();
    BufferedReader bufferedReader = null;
    try {
        InputStream inputStream = request.getInputStream();
        if (inputStream != null) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            char[] charBuffer = new char[128];
            int bytesRead = -1;
            while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
                stringBuilder.append(charBuffer, 0, bytesRead);
            }
        } else {
            stringBuilder.append("");
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    String body = stringBuilder.toString();

0 个答案:

没有答案