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

📄 edcode.java~1~

📁 1. 消息即时通信 2. 消息发送实现一对一、一对多等多种发送模式 3. 发送的消息实现多彩文本编辑
💻 JAVA~1~
字号:
package system;
import java.io.*;
/**
 * 此处插入类型描述。
 * 创建日期:(2005-1-27 14:54:05)
 * @author:Administrator
 */

public class EDCode {
    private static final String TABLEBASE64 ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    private static final char[] ENCODE_TABLE =
        new char[] {
            '0',
            '1',
            '2',
            '3',
            '4',
            '5',
            '6',
            '7',
            '8',
            '9',
            'A',
            'B',
            'C',
            'D',
            'E',
            'F' };
    public static String encodeBase64(String Value) {
        ByteArrayOutputStream o = new ByteArrayOutputStream();
        byte d[] = new byte[4];
        try {
            int count = 0;
            for (byte x[] = Value.getBytes(); count < x.length;) {
                byte c = x[count];
                count++;
                d[0] = (byte) ((c & 0xfc) >> 2);
                d[1] = (byte) ((c & 0x3) << 4);
                if (count < x.length) {
                    c = x[count];
                    count++;
                    d[1] = (byte) (d[1] + (byte) ((c & 0xf0) >> 4));
                    d[2] = (byte) ((c & 0xf) << 2);
                    if (count < x.length) {
                        c = x[count];
                        count++;
                        d[2] = (byte) (d[2] + ((c & 0xc0) >> 6));
                        d[3] = (byte) (c & 0x3f);
                    } else {
                        d[3] = 64;
                    }
                } else {
                    d[2] = 64;
                    d[3] = 64;
                }
                int n = 0;
                while (n <= 3) {
                    o.write(TABLEBASE64.charAt(d[n]));
                    n++;
                }
            }

        } catch (StringIndexOutOfBoundsException e) {
            System.out.println(e.toString());
        }
        return o.toString();
    }

    public static String decodeBase64(String Value) {
        ByteArrayOutputStream o = new ByteArrayOutputStream();
        byte d[] = new byte[4];
        try {
            int count = 0;
            byte x[] = Value.getBytes();
            do {
                if (count >= x.length)
                    break;
                for (int n = 0; n <= 3; n++) {
                    if (count >= x.length) {
                        d[n] = 64;
                    } else {
                        int y = TABLEBASE64.indexOf(x[count]);
                        if (y < 0)
                            y = 65;
                        d[n] = (byte) y;
                    }
                    count++;
                }

                o.write((byte) (((d[0] & 0x3f) << 2) + ((d[1] & 0x30) >> 4)));
                if (d[2] != 64) {
                    o.write((byte) (((d[1] & 0xf) << 4) + ((d[2] & 0x3c) >> 2)));
                    if (d[3] != 64)
                        o.write((byte) (((d[2] & 0x3) << 6) + (d[3] & 0x3f)));
                }
            } while (true);
        } catch (StringIndexOutOfBoundsException e) {
            System.out.println(e.toString());
        }
        return o.toString();
    }

    public static String escape(String src) {
        int i;
        char j;
        StringBuffer tmp = new StringBuffer();
        tmp.ensureCapacity(src.length() * 6);

        for (i = 0; i < src.length(); i++) {
            j = src.charAt(i);
            if (Character.isDigit(j)
                || Character.isLowerCase(j)
                || Character.isUpperCase(j))
                tmp.append(j);
            else if (j < 256) {
                tmp.append("%");
                if (j < 16)
                    tmp.append("0");
                tmp.append(Integer.toString(j, 16));
            } else {
                tmp.append("%u");
                tmp.append(Integer.toString(j, 16));
            }
        }
        return tmp.toString();
    }

    public static String unescape(String src) {
        StringBuffer tmp = new StringBuffer();
        tmp.ensureCapacity(src.length());
        int lastPos = 0, pos = 0;
        char ch;
        while (lastPos < src.length()) {
            pos = src.indexOf("%", lastPos);
            if (pos == lastPos) {
                if (src.charAt(pos + 1) == 'u') {
                    ch = (char) Integer.parseInt(src.substring(pos + 2, pos + 6), 16);
                    tmp.append(ch);
                    lastPos = pos + 6;
                } else {
                    ch = (char) Integer.parseInt(src.substring(pos + 1, pos + 3), 16);
                    tmp.append(ch);
                    lastPos = pos + 3;
                }
            } else {
                if (pos == -1) {
                    tmp.append(src.substring(lastPos));
                    lastPos = src.length();
                } else {
                    tmp.append(src.substring(lastPos, pos));
                    lastPos = pos;
                }
            }
        }
        return tmp.toString();
    }

    public static String URLEncode(String s) {
        byte[] bytes = s.getBytes();
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < bytes.length; i++) {
            byte c = bytes[i];
            if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
                result.append((char) c);
            else {
                result.append('%');
                result.append(ENCODE_TABLE[(c >> 4) & 0x0f]);
                result.append(ENCODE_TABLE[c & 0x0f]);
            }
        }
        return result.toString();
    }

    public static String URLDecode(String source, String enc) {
        if (source == null)
            return (null);
        byte[] bytes = source.getBytes();
        int len = bytes.length;
        int ix = 0;
        int ox = 0;
        while (ix < len) {
            byte b = bytes[ix++]; // Get byte to test
            if (b == '+') {
                b = (byte) ' ';
            } else if (b == '%') {
                b = (byte) ((convertHexDigit(bytes[ix++]) << 4) + convertHexDigit(bytes[ix++]));
            }
            bytes[ox++] = b;
        }
        if (enc != null) {
            try {
                return new String(bytes, 0, ox, enc);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return new String(bytes, 0, ox);
    }

    /**
     * Convert a byte character value to hexidecimal digit value.
     *
     * @param b the character value byte
     */
    private static byte convertHexDigit(byte b) {
        if ((b >= '0') && (b <= '9'))
            return (byte) (b - '0');
        if ((b >= 'a') && (b <= 'f'))
            return (byte) (b - 'a' + 10);
        if ((b >= 'A') && (b <= 'F'))
            return (byte) (b - 'A' + 10);
        return 0;
    }

    public static int byteIndexOf(byte[] source, String search, int start) {
        return byteIndexOf(source, search.getBytes(), start);
    }

    public static int byteIndexOf(byte[] source, byte[] search, int start) {
        int i;
        if (search.length == 0) {
            return 0;
        }
        int max = source.length - search.length;
        if (max < 0)
            return -1;
        if (start > max)
            return -1;
        if (start < 0)
            start = 0;
        // 在source中找到search的第一个元素
        searchForFirst : for (i = start; i <= max; i++) {
            if (source[i] == search[0]) {
                //找到了search中的第一个元素后,比较剩余的部分是否相等
                int k = 1;
                while (k < search.length) {
                    if (source[k + i] != search[k]) {
                        continue searchForFirst;
                    }
                    k++;
                }
                return i;
            }
        }
        return -1;
    }

    public static byte[] subBytes(byte[] source, int from, int end) {
        byte[] result = new byte[end - from];
        System.arraycopy(source, from, result, 0, end - from);
        return result;
    }

    public static String subBytesString(byte[] source, int from, int end) {
        return new String(subBytes(source, from, end));
    }

    public static int bytesLen(String s) {
        return s.getBytes().length;
    }

    public static String decoded(String needTreatStr) {
        if (needTreatStr == null)
            return needTreatStr;
        try {
            byte temp_t[] = needTreatStr.getBytes("ISO8859-1");
           //byte temp_t[] = needTreatStr.getBytes("GB2312");
            return new String(temp_t);
        } catch (UnsupportedEncodingException ex) {
            return "";
        }
    }

}

⌨️ 快捷键说明

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