当前位置: 首页>>代码示例>>Java>>正文


Java BlockGuard类代码示例

本文整理汇总了Java中dalvik.system.BlockGuard的典型用法代码示例。如果您正苦于以下问题:Java BlockGuard类的具体用法?Java BlockGuard怎么用?Java BlockGuard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BlockGuard类属于dalvik.system包,在下文中一共展示了BlockGuard类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lookupHostByName

import dalvik.system.BlockGuard; //导入依赖的package包/类
/**
 * Resolves a hostname to its IP addresses using a cache.
 *
 * @param host the hostname to resolve.
 * @return the IP addresses of the host.
 */
private static InetAddress[] lookupHostByName(String host) throws UnknownHostException {
    BlockGuard.getThreadPolicy().onNetwork();
    // Do we have a result cached?
    InetAddress[] cachedResult = addressCache.get(host);
    if (cachedResult != null) {
        if (cachedResult.length > 0) {
            // A cached positive result.
            return cachedResult;
        } else {
            // A cached negative result.
            throw new UnknownHostException(host);
        }
    }
    try {
        InetAddress[] addresses = bytesToInetAddresses(getaddrinfo(host), host);
        addressCache.put(host, addresses);
        return addresses;
    } catch (UnknownHostException e) {
        addressCache.putUnknownHost(host);
        throw new UnknownHostException(host);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:29,代码来源:InetAddress.java

示例2: read

import dalvik.system.BlockGuard; //导入依赖的package包/类
/**
 * Method acts as described in spec for superclass.
 * @see java.io.InputStream#read(byte[],int,int)
 */
@Override
public int read(byte[] b, int off, int len) throws IOException {
    BlockGuard.getThreadPolicy().onNetwork();
    synchronized (readLock) {
        checkOpen();
        if (b == null) {
            throw new NullPointerException("b == null");
        }
        if ((len | off) < 0 || len > b.length - off) {
            throw new IndexOutOfBoundsException();
        }
        if (0 == len) {
            return 0;
        }
        return NativeCrypto.SSL_read(sslNativePointer, fd, OpenSSLSocketImpl.this,
                                     b, off, len, getSoTimeout());
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:OpenSSLSocketImpl.java

示例3: write

import dalvik.system.BlockGuard; //导入依赖的package包/类
/**
 * Method acts as described in spec for superclass.
 * @see java.io.OutputStream#write(byte[],int,int)
 */
@Override
public void write(byte[] b, int start, int len) throws IOException {
    BlockGuard.getThreadPolicy().onNetwork();
    synchronized (writeLock) {
        checkOpen();
        if (b == null) {
            throw new NullPointerException("b == null");
        }
        if ((len | start) < 0 || len > b.length - start) {
            throw new IndexOutOfBoundsException();
        }
        if (len == 0) {
            return;
        }
        NativeCrypto.SSL_write(sslNativePointer, fd, OpenSSLSocketImpl.this, b, start, len);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:OpenSSLSocketImpl.java

示例4: applyBlockGuardPolicy

import dalvik.system.BlockGuard; //导入依赖的package包/类
private void applyBlockGuardPolicy(PreparedStatement statement) {
    if (!mConfiguration.isInMemoryDb()) {
        if (statement.mReadOnly) {
            BlockGuard.getThreadPolicy().onReadFromDisk();
        } else {
            BlockGuard.getThreadPolicy().onWriteToDisk();
        }
    }
}
 
开发者ID:doppllib,项目名称:core-doppl,代码行数:10,代码来源:SQLiteConnection.java

示例5: getHostByAddrImpl

import dalvik.system.BlockGuard; //导入依赖的package包/类
private static InetAddress getHostByAddrImpl(InetAddress address) throws UnknownHostException {
    BlockGuard.getThreadPolicy().onNetwork();
    try {
        String hostname = Libcore.os.getnameinfo(address, NI_NAMEREQD);
        return makeInetAddress(address.ipaddress.clone(), hostname);
    } catch (GaiException gaiException) {
        throw gaiException.rethrowAsUnknownHostException();
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:10,代码来源:InetAddress.java

示例6: getHostByAddrImpl

import dalvik.system.BlockGuard; //导入依赖的package包/类
/**
 * Query the IP stack for the host address. The host is in address form.
 *
 * @param addr
 *            the host address to lookup.
 * @throws UnknownHostException
 *             if an error occurs during lookup.
 */
static InetAddress getHostByAddrImpl(byte[] addr)
        throws UnknownHostException {
    BlockGuard.getThreadPolicy().onNetwork();
    if (addr.length == 4) {
        return new Inet4Address(addr, getnameinfo(addr));
    } else if (addr.length == 16) {
        return new Inet6Address(addr, getnameinfo(addr));
    } else {
        throw new UnknownHostException(wrongAddressLength());
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:InetAddress.java

示例7: blockGuardOnNetwork

import dalvik.system.BlockGuard; //导入依赖的package包/类
static void blockGuardOnNetwork() {
    BlockGuard.getThreadPolicy().onNetwork();
}
 
开发者ID:google,项目名称:conscrypt,代码行数:4,代码来源:Platform.java

示例8: blockGuardOnNetwork

import dalvik.system.BlockGuard; //导入依赖的package包/类
public static void blockGuardOnNetwork() {
    BlockGuard.getThreadPolicy().onNetwork();
}
 
开发者ID:google,项目名称:conscrypt,代码行数:4,代码来源:Platform.java

示例9: lookupHostByName

import dalvik.system.BlockGuard; //导入依赖的package包/类
/**
 * Resolves a hostname to its IP addresses using a cache.
 *
 * @param host the hostname to resolve.
 * @return the IP addresses of the host.
 */
private static InetAddress[] lookupHostByName(String host) throws UnknownHostException {
    BlockGuard.getThreadPolicy().onNetwork();
    // Do we have a result cached?
    Object cachedResult = addressCache.get(host);
    if (cachedResult != null) {
        if (cachedResult instanceof InetAddress[]) {
            // A cached positive result.
            return (InetAddress[]) cachedResult;
        } else {
            // A cached negative result.
            throw new UnknownHostException((String) cachedResult);
        }
    }
    try {
        StructAddrinfo hints = new StructAddrinfo();
        hints.ai_flags = AI_ADDRCONFIG;
        hints.ai_family = AF_UNSPEC;
        // If we don't specify a socket type, every address will appear twice, once
        // for SOCK_STREAM and one for SOCK_DGRAM. Since we do not return the family
        // anyway, just pick one.
        hints.ai_socktype = SOCK_STREAM;
        InetAddress[] addresses = Libcore.os.getaddrinfo(host, hints);
        // TODO: should getaddrinfo set the hostname of the InetAddresses it returns?
        for (InetAddress address : addresses) {
            address.hostName = host;
        }
        addressCache.put(host, addresses);
        return addresses;
    } catch (GaiException gaiException) {
        // If the failure appears to have been a lack of INTERNET permission, throw a clear
        // SecurityException to aid in debugging this common mistake.
        // http://code.google.com/p/android/issues/detail?id=15722
        if (gaiException.getCause() instanceof ErrnoException) {
            if (((ErrnoException) gaiException.getCause()).errno == EACCES) {
                throw new SecurityException("Permission denied (missing INTERNET permission?)", gaiException);
            }
        }
        // Otherwise, throw an UnknownHostException.
        String detailMessage = "Unable to resolve host \"" + host + "\": " + Libcore.os.gai_strerror(gaiException.error);
        addressCache.putUnknownHost(host, detailMessage);
        throw gaiException.rethrowAsUnknownHostException(detailMessage);
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:50,代码来源:InetAddress.java

示例10: close

import dalvik.system.BlockGuard; //导入依赖的package包/类
/**
 * Closes the SSL socket. Once closed, a socket is not available for further
 * use anymore under any circumstance. A new socket must be created.
 *
 * @throws <code>IOException</code> if an I/O error happens during the
 *             socket's closure.
 */
@Override
public void close() throws IOException {
    // TODO: Close SSL sockets using a background thread so they close
    // gracefully.

    synchronized (handshakeLock) {
        if (!handshakeStarted) {
            // prevent further attemps to start handshake
            handshakeStarted = true;

            synchronized (this) {
                free();

                if (socket != this) {
                    if (autoClose && !socket.isClosed()) socket.close();
                } else {
                    if (!super.isClosed()) super.close();
                }
            }

            return;
        }
    }

    NativeCrypto.SSL_interrupt(sslNativePointer);

    synchronized (this) {
        synchronized (writeLock) {
            synchronized (readLock) {

                // Shut down the SSL connection, per se.
                try {
                    if (handshakeStarted) {
                        BlockGuard.getThreadPolicy().onNetwork();
                        NativeCrypto.SSL_shutdown(sslNativePointer, fd, this);
                    }
                } catch (IOException ignored) {
                    /*
                     * Note that although close() can throw
                     * IOException, the RI does not throw if there
                     * is problem sending a "close notify" which
                     * can happen if the underlying socket is closed.
                     */
                }

                /*
                 * Even if the above call failed, it is still safe to free
                 * the native structs, and we need to do so lest we leak
                 * memory.
                 */
                free();

                if (socket != this) {
                    if (autoClose && !socket.isClosed())
                        socket.close();
                } else {
                    if (!super.isClosed())
                        super.close();
                }
            }
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:71,代码来源:OpenSSLSocketImpl.java


注:本文中的dalvik.system.BlockGuard类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。