FileDocCategorySizeDatePackage
NetUtil.javaAPI DocAndroid 1.5 API4000Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.net

NetUtil

public class NetUtil extends Object

Fields Summary
Constructors Summary
Methods Summary
static intbytesToInt(byte[] bytes, int start)

        /*
         * First mask the byte with 255, as when a negative signed byte converts
         * to an integer, it has bits on in the first 3 bytes, we are only
         * concerned about the right-most 8 bits. Then shift the rightmost byte
         * to align with its position in the integer.
         */
        int value = ((bytes[start + 3] & 255)) | ((bytes[start + 2] & 255) << 8)
                | ((bytes[start + 1] & 255) << 16) | ((bytes[start] & 255) << 24);
        return value;
    
public static java.util.ListgetProxyList(java.net.URI uri)
Gets proxy list according to the URI by system ProxySelector.

param
uri
return
a list of proxy for the URI. Returns null if no proxy is available.

        // use system default selector to get proxy list
        ProxySelector selector = ProxySelector.getDefault();
        if (null == selector) {
            return null;
        }
        return selector.select(uri);
    
static voidintToBytes(int value, byte[] bytes, int start)

        /*
         * Shift the int so the current byte is right-most Use a byte mask of
         * 255 to single out the last byte.
         */
        bytes[start] = (byte) ((value >> 24) & 255);
        bytes[start + 1] = (byte) ((value >> 16) & 255);
        bytes[start + 2] = (byte) ((value >> 8) & 255);
        bytes[start + 3] = (byte) (value & 255);
    
public static booleanpreferIPv4Stack()
Answer whether to prefer IPV4 stack

return
boolean

        final Action a = new Action("java.net.preferIPv4Stack");//$NON-NLS-1$
        return AccessController.doPrivileged(a).booleanValue();
    
public static booleanpreferIPv6Addresses()
Answer whether to prefer IPV6 address

return
boolean

        final Action a = new Action("java.net.preferIPv6Addresses");//$NON-NLS-1$
        return AccessController.doPrivileged(a).booleanValue();
    
public static booleanusingSocks(java.net.Proxy proxy)
Returns whether to use a SOCKS proxy.

param
proxy java.net.Proxy proxy is used to determine whether using SOCKS proxy.
return
true if only the type of proxy is Proxy.Type.SOCKS.

        if (null != proxy && Proxy.Type.SOCKS == proxy.type()) {
            return true;
        }
        return false;