utilities.java

来自「Sony Ericsson手机上的Facebook客户端全套代码」· Java 代码 · 共 84 行

JAVA
84
字号
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Utilities.java

package com.sonyericsson.fb.utils;


public class Utilities
{

    public Utilities()
    {
    }

    public static String toHexString(byte array[])
    {
        return toHexString(array, 0, array.length);
    }

    public static String toHexString(byte array[], int offset, int length)
    {
        if(array == null || array.length == 0 || length > array.length || offset + length > array.length)
            return "";
        StringBuffer buffer = new StringBuffer(2 * length);
        for(int i = offset; i < length; i++)
            buffer.append(toHexString(array[i]));

        return buffer.toString();
    }

    public static String toHexString(byte b)
    {
        int value = b & 0xff;
        StringBuffer buffer = new StringBuffer("");
        buffer.append(hexchars[value >> 4]);
        buffer.append(hexchars[value & 0xf]);
        return buffer.toString();
    }

    public static String encodeUrl(String url)
    {
        StringBuffer buffer = new StringBuffer();
        int length = url.length();
        for(int i = 0; i < length; i++)
        {
            char c = url.charAt(i);
            if('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9' || c == '-' || c == '_' || c == '.' || c == '!' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')')
            {
                buffer.append(c);
                continue;
            }
            if(c == ' ')
            {
                buffer.append('+');
                continue;
            }
            if(c <= '\177')
            {
                buffer.append("%" + toHexString((byte)c));
                continue;
            }
            if(c <= '\u07FF')
            {
                buffer.append("%" + toHexString((byte)(0xc0 | c >> 6)));
                buffer.append("%" + toHexString((byte)(0x80 | c & 0x3f)));
            } else
            {
                buffer.append("%" + toHexString((byte)(0xe0 | c >> 12)));
                buffer.append("%" + toHexString((byte)(0x80 | c >> 6 & 0x3f)));
                buffer.append("%" + toHexString((byte)(0x80 | c & 0x3f)));
            }
        }

        return buffer.toString();
    }

    private static final char hexchars[] = {
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
        'a', 'b', 'c', 'd', 'e', 'f'
    };

}

⌨️ 快捷键说明

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