⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatutils.java

📁 ICE3.3.0--聊天程序服务器端demo
💻 JAVA
字号:
// **********************************************************************//// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.//// This copy of Chat Demo is licensed to you under the terms// described in the CHAT_DEMO_LICENSE file included in this// distribution.//// **********************************************************************package ChatDemoGUI;import java.util.Date;import java.util.TimeZone;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.io.StringWriter;import java.io.PrintWriter;public class ChatUtils{    //    // This function unescapes HTML entities in the data string    // and return the unescaped string.    //    public static String unstripHtml(String data)    {        data = data.replace("&quot;", "\"");        data = data.replace("&#39;", "'");        data = data.replace("&lt;", "<");        data = data.replace("&gt;", ">");        data = data.replace("&amp;", "&");        return data;    }    public static String formatTimestamp(long timestamp)    {        DateFormat dtf = new SimpleDateFormat("HH:mm:ss");        dtf.setTimeZone(TimeZone.getDefault());        return dtf.format(new Date(timestamp));    }    public static String formatUsername(String in)    {        try        {            in = in.substring(0, 1).toUpperCase() + in.substring(1, in.length()).toLowerCase();        }        catch(IndexOutOfBoundsException ex)        {        }        return in;    }    public static void validateMessage(String message) throws Chat.InvalidMessageException    {        if(message.length() > _maxMessageSize)        {            Chat.InvalidMessageException ex = new Chat.InvalidMessageException();            ex.reason = "Message length exceeded, maximum length is " + _maxMessageSize + " characters.";            throw ex;        }    }    public static String stack2string(Exception e)    {        try        {            StringWriter sw = new StringWriter();            PrintWriter pw = new PrintWriter(sw);            e.printStackTrace(pw);            return sw.toString();        }        catch(Exception e2)        {            return e.toString();        }    }    private static final int _maxMessageSize = 1024;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -