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


Java AddressUtil.getDirectBufferAddress方法代码示例

本文整理汇总了Java中org.apache.harmony.nio.AddressUtil.getDirectBufferAddress方法的典型用法代码示例。如果您正苦于以下问题:Java AddressUtil.getDirectBufferAddress方法的具体用法?Java AddressUtil.getDirectBufferAddress怎么用?Java AddressUtil.getDirectBufferAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.harmony.nio.AddressUtil的用法示例。


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

示例1: writeImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private int writeImpl(ByteBuffer buf) throws IOException {
    synchronized (writeLock) {
        int result = 0;
        try {
            begin();
            int length = buf.remaining();
            int start = buf.position();

            if (buf.isDirect()) {
                int address = AddressUtil.getDirectBufferAddress(buf);
                result = networkSystem.sendDirect(fd, address, start, length, 0, null);
            } else {
                // buf is assured to have array.
                start += buf.arrayOffset();
                result = networkSystem.send(fd, buf.array(), start, length, 0, null);
            }
            return result;
        } finally {
            end(result > 0);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:DatagramChannelImpl.java

示例2: receiveDirectImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private SocketAddress receiveDirectImpl(ByteBuffer target, boolean loop) throws IOException {
    SocketAddress retAddr = null;
    DatagramPacket receivePacket = new DatagramPacket(stubArray, 0);
    int oldposition = target.position();
    int received = 0;
    do {
        int address = AddressUtil.getDirectBufferAddress(target);
        received = networkSystem.recvDirect(fd, receivePacket, address,
                target.position(), target.remaining(), false, isConnected());

        // security check
        SecurityManager sm = System.getSecurityManager();
        if (!isConnected() && null != sm) {
            try {
                sm.checkAccept(receivePacket.getAddress().getHostAddress(),
                        receivePacket.getPort());
            } catch (SecurityException e) {
                // do discard the datagram packet
                receivePacket = null;
            }
        }
        if (null != receivePacket && null != receivePacket.getAddress()) {
            // copy the data of received packet
            if (received > 0) {
                target.position(oldposition + received);
            }
            retAddr = receivePacket.getSocketAddress();
            break;
        }
    } while (loop);
    return retAddr;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:33,代码来源:DatagramChannelImpl.java

示例3: readImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private int readImpl(ByteBuffer readBuffer) throws IOException {
    synchronized (readLock) {
        int readCount = 0;
        try {
            begin();
            int start = readBuffer.position();
            int length = readBuffer.remaining();
            if (readBuffer.isDirect()) {
                int address = AddressUtil.getDirectBufferAddress(readBuffer);
                readCount = networkSystem.recvDirect(fd, null, address, start, length,
                        false, isConnected());
            } else {
                // the target is assured to have array.
                byte[] target = readBuffer.array();
                start += readBuffer.arrayOffset();
                readCount = networkSystem.recv(fd, null, target, start, length, false,
                        isConnected());
            }
            return readCount;
        } catch (InterruptedIOException e) {
            // InterruptedIOException will be thrown when timeout.
            return 0;
        } finally {
            end(readCount > 0);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:28,代码来源:DatagramChannelImpl.java

示例4: readImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
/**
 * Read from channel, and store the result in the target.
 *
 * @param target
 *            output parameter
 */
private int readImpl(ByteBuffer target) throws IOException {
    synchronized (readLock) {
        int readCount = 0;
        try {
            if (isBlocking()) {
                begin();
            }
            int offset = target.position();
            int length = target.remaining();
            if (target.isDirect()) {
                // BEGIN android-changed
                // changed address from long to int
                int address = AddressUtil.getDirectBufferAddress(target);
                readCount = networkSystem.readDirect(fd, address + offset, length);
                // END android-changed
            } else {
                // target is assured to have array.
                byte[] array = target.array();
                offset += target.arrayOffset();
                readCount = networkSystem.read(fd, array, offset, length);
            }
            return readCount;
        } finally {
            if (isBlocking()) {
                end(readCount > 0);
            }
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:36,代码来源:SocketChannelImpl.java

示例5: writeImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private int writeImpl(ByteBuffer buf) throws IOException {
    synchronized (writeLock) {
        int result = 0;
        try {
            begin();
            int length = buf.remaining();
            int start = buf.position();

            if (buf.isDirect()) {
                long address = AddressUtil.getDirectBufferAddress(buf);
                result = networkSystem.sendConnectedDatagramDirect(fd,
                        address, start, length, isBound);
            } else {
                // buf is assured to have array.
                start += buf.arrayOffset();
                result = networkSystem.sendConnectedDatagram(fd, buf
                        .array(), start, length, isBound);
            }
            return result;
        } catch (SocketException e) {
            if (e.getCause() instanceof ErrorCodeException) {
                if (ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK == ((ErrorCodeException) e
                        .getCause()).getErrorCode()) {
                    return result;
                }
            }
            throw e;
        } finally {
            end(result > 0);
        }
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:33,代码来源:DatagramChannelImpl.java

示例6: readImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
/**
 * Read from channel, and store the result in the target.
 * 
 * @param target
 *            output parameter
 */
private int readImpl(ByteBuffer target) throws IOException {
    synchronized (readLock) {
        int readCount = 0;
        try {
            if (isBlocking()) {
                begin();
            }
            int offset = target.position();
            int length = target.remaining();
            if (target.isDirect()) {
                long address = AddressUtil.getDirectBufferAddress(target);
                readCount = networkSystem.readDirect(fd, address + offset,
                        length, (isBlocking() ? TIMEOUT_BLOCK
                                : TIMEOUT_NONBLOCK));
            } else {
                // target is assured to have array.
                byte[] array = target.array();
                offset += target.arrayOffset();
                readCount = networkSystem.read(fd, array, offset, length,
                        (isBlocking() ? TIMEOUT_BLOCK : TIMEOUT_NONBLOCK));
            }
            return readCount;
        } finally {
            if (isBlocking()) {
                end(readCount > 0);
            }
        }
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:36,代码来源:SocketChannelImpl.java

示例7: readImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private int readImpl(ByteBuffer readBuffer) throws IOException {
    synchronized(readLock){
        int readCount = 0;
        try {
            begin();
            // timeout == 0 means block read.
            // DEFAULT_TIMEOUT is used in non-block mode.
            int timeout = isBlocking() ? 0 : DEFAULT_TIMEOUT;
            int start = readBuffer.position();
            int length = readBuffer.remaining();
            if (readBuffer.isDirect()) {
                long address = AddressUtil.getDirectBufferAddress(readBuffer);
                if (isConnected()) {
                    readCount = networkSystem.recvConnectedDatagramDirect(fd,
                            null, address, start, length, timeout, false);
                } else {
                    readCount = networkSystem.receiveDatagramDirect(fd,
                            null, address, start, length, timeout, false);
                }
            } else {
                // the target is assured to have array.
                byte[] target = readBuffer.array();
                start += readBuffer.arrayOffset();
                if (isConnected()) {
                    readCount = networkSystem.recvConnectedDatagram(fd, null,
                            target, start, length, timeout, false);
                } else {
                    readCount = networkSystem.receiveDatagram(fd, null, target,
                            start, length, timeout, false);
                }
            }
            return readCount;
        } catch (InterruptedIOException e) {
            // InterruptedIOException will be thrown when timeout.
            return 0;
        } finally {
            end(readCount > 0);
        }
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:41,代码来源:DatagramChannelImpl.java

示例8: writeImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private int writeImpl(ByteBuffer buf) throws IOException {
    synchronized(writeLock){
        int result = 0;
        try {
            begin();
            int length = buf.remaining();
            int start = buf.position();

            if (buf.isDirect()) {
                long address = AddressUtil.getDirectBufferAddress(buf);
                result = networkSystem.sendConnectedDatagramDirect(fd, address,
                        start, length, isBound);
            } else {
                // buf is assured to have array.
                start += buf.arrayOffset();
                result = networkSystem.sendConnectedDatagram(fd, buf.array(),
                        start, length, isBound);
            }
            return result;
        } catch (SocketException e) {
            if (e.getCause() instanceof ErrorCodeException) {
                if (ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK == ((ErrorCodeException) e
                        .getCause()).getErrorCode()) {
                    return result;
                }
            }
            throw e;
        } finally {
            end(result > 0);
        }
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:33,代码来源:DatagramChannelImpl.java

示例9: readImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private int readImpl(ByteBuffer target) throws IOException {
    synchronized(readLock){
        int readCount = 0;
        try {
            if (isBlocking()) {
                begin();
            }
            int offset = target.position();
            int length = target.remaining();
            if (target.isDirect()) {
                long address = AddressUtil.getDirectBufferAddress(target);
                readCount = networkSystem.readDirect(fd, address, offset,
                        length, (isBlocking() ? TIMEOUT_BLOCK
                                : TIMEOUT_NONBLOCK));
            } else {
                // target is assured to have array.
                byte[] array = target.array();
                offset += target.arrayOffset();
                readCount = networkSystem.read(fd, array, offset, length,
                        (isBlocking() ? TIMEOUT_BLOCK : TIMEOUT_NONBLOCK));
            }
            return readCount;
        } finally {
            if (isBlocking()) {
                end(readCount > 0);
            }
        }
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:30,代码来源:SocketChannelImpl.java

示例10: send

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
/**
 * @see java.nio.channels.DatagramChannel#send(java.nio.ByteBuffer,
 *      java.net.SocketAddress)
 */
@Override
public int send(ByteBuffer source, SocketAddress socketAddress) throws IOException {
    // must not null
    checkNotNull(source);
    // must open
    checkOpen();

    // transfer socketAddress
    InetSocketAddress isa = (InetSocketAddress) socketAddress;
    if (null == isa.getAddress()) {
        throw new IOException();
    }

    if (isConnected()) {
        if (!connectAddress.equals(isa)) {
            throw new IllegalArgumentException();
        }
    } else {
        // not connected, check security
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            if (isa.getAddress().isMulticastAddress()) {
                sm.checkMulticast(isa.getAddress());
            } else {
                sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort());
            }
        }
    }

    // the return value.
    int sendCount = 0;
    try {
        begin();
        byte[] array = null;
        int length = source.remaining();
        int oldposition = source.position();
        int start = oldposition;
        if (source.isDirect()) {
            synchronized (writeLock) {
                int data_address = AddressUtil.getDirectBufferAddress(source);
                sendCount = networkSystem.sendDirect(fd, data_address, start, length,
                        isa.getPort(), isa.getAddress());
            }
        } else {
            if (source.hasArray()) {
                array = source.array();
                start += source.arrayOffset();
            } else {
                array = new byte[length];
                source.get(array);
                start = 0;
            }
            synchronized (writeLock) {
                sendCount = networkSystem.send(fd, array, start, length,
                        isa.getPort(), isa.getAddress());
            }
        }
        source.position(oldposition + sendCount);
        return sendCount;
    } finally {
        end(sendCount >= 0);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:68,代码来源:DatagramChannelImpl.java

示例11: receiveDirectImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private SocketAddress receiveDirectImpl(ByteBuffer target, boolean loop)
        throws IOException {
    SocketAddress retAddr = null;
    DatagramPacket receivePacket = new DatagramPacket(stubArray, 0);
    int oldposition = target.position();
    int received = 0;
    do {
        long address = AddressUtil.getDirectBufferAddress(target);
        if (isConnected()) {
            received = networkSystem.recvConnectedDatagramDirect(fd,
                    receivePacket, address, target.position(), target
                            .remaining(), isBlocking() ? 0
                            : DEFAULT_TIMEOUT, false);
        } else {
            received = networkSystem.receiveDatagramDirect(fd,
                    receivePacket, address, target.position(), target
                            .remaining(), isBlocking() ? 0
                            : DEFAULT_TIMEOUT, false);
        }

        // security check
        SecurityManager sm = System.getSecurityManager();
        if (!isConnected() && null != sm) {
            try {
                sm.checkAccept(receivePacket.getAddress().getHostAddress(),
                        receivePacket.getPort());
            } catch (SecurityException e) {
                // do discard the datagram packet
                receivePacket = null;
            }
        }
        if (null != receivePacket && null != receivePacket.getAddress()) {
            // copy the data of received packet
            if (received > 0) {
                target.position(oldposition + received);
            }
            retAddr = receivePacket.getSocketAddress();
            break;
        }
    } while (loop);
    return retAddr;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:43,代码来源:DatagramChannelImpl.java

示例12: readImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private int readImpl(ByteBuffer readBuffer) throws IOException {
    synchronized (readLock) {
        int readCount = 0;
        try {
            begin();
            // timeout == 0 means block read.
            // DEFAULT_TIMEOUT is used in non-block mode.
            int timeout = isBlocking() ? 0 : DEFAULT_TIMEOUT;
            int start = readBuffer.position();
            int length = readBuffer.remaining();
            if (readBuffer.isDirect()) {
                long address = AddressUtil
                        .getDirectBufferAddress(readBuffer);
                if (isConnected()) {
                    readCount = networkSystem.recvConnectedDatagramDirect(
                            fd, null, address, start, length, timeout,
                            false);
                } else {
                    readCount = networkSystem.receiveDatagramDirect(fd,
                            null, address, start, length, timeout, false);
                }
            } else {
                // the target is assured to have array.
                byte[] target = readBuffer.array();
                start += readBuffer.arrayOffset();
                if (isConnected()) {
                    readCount = networkSystem.recvConnectedDatagram(fd,
                            null, target, start, length, timeout, false);
                } else {
                    readCount = networkSystem.receiveDatagram(fd, null,
                            target, start, length, timeout, false);
                }
            }
            return readCount;
        } catch (InterruptedIOException e) {
            // InterruptedIOException will be thrown when timeout.
            return 0;
        } finally {
            end(readCount > 0);
        }
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:43,代码来源:DatagramChannelImpl.java

示例13: receiveDirectImpl

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
private SocketAddress receiveDirectImpl(ByteBuffer target, boolean loop) throws IOException
{
    SocketAddress retAddr = null;  
    DatagramPacket receivePacket = new DatagramPacket(
            stubArray, 0);
    int oldposition = target.position();
    int received = 0;
    do {
        long address = AddressUtil.getDirectBufferAddress(target);
        if (isConnected()) {
            received = networkSystem.recvConnectedDatagramDirect(fd, receivePacket,
                    address, target.position(),
                    target.remaining(), isBlocking() ? 0
                            : DEFAULT_TIMEOUT, false);
        } else {
            received = networkSystem.receiveDatagramDirect(fd, receivePacket,
                    address, target.position(),
                    target.remaining(), isBlocking() ? 0
                            : DEFAULT_TIMEOUT, false);
        }

        // security check
        SecurityManager sm = System.getSecurityManager();
        if (!isConnected() && null != sm) {
            try {
                sm.checkAccept(receivePacket.getAddress()
                        .getHostAddress(), receivePacket.getPort());
            } catch (SecurityException e) {
                // do discard the datagram packet
                receivePacket = null;
            }
        }
        if (null != receivePacket
                && null != receivePacket.getAddress()) {
            // copy the data of received packet
            if (received > 0) {
                target.position(oldposition + received);
            }
            retAddr = receivePacket.getSocketAddress();
            break;
        }
    } while (loop);
    return retAddr;
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:45,代码来源:DatagramChannelImpl.java

示例14: send

import org.apache.harmony.nio.AddressUtil; //导入方法依赖的package包/类
@Override
public int send(ByteBuffer source, SocketAddress socketAddress)
        throws IOException {
    // must not null
    checkNotNull(source);
    // must open
    checkOpen();

    // transfer socketAddress
    InetSocketAddress isa = (InetSocketAddress) socketAddress;
    if (null == isa.getAddress()) {
        throw new IOException();
    }

    if (isConnected()) {
        if (!connectAddress.equals(isa)) {
            throw new IllegalArgumentException();
        }
    } else {
        // not connected, check security
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            if (isa.getAddress().isMulticastAddress()) {
                sm.checkMulticast(isa.getAddress());
            } else {
                sm.checkConnect(isa.getAddress().getHostAddress(), isa
                        .getPort());
            }
        }
    }

    // the return value.
    int sendCount = 0;
    try {
        begin();
        byte[] array = null;
        int length = source.remaining();
        int oldposition = source.position();
        int start = oldposition;
        if (source.isDirect()) {
            synchronized (writeLock) {
                long data_address = AddressUtil
                        .getDirectBufferAddress(source);
                sendCount = networkSystem.sendDatagramDirect(fd,
                        data_address, start, length, isa.getPort(), false,
                        trafficClass, isa.getAddress());
            }
        } else {
            if (source.hasArray()) {
                array = source.array();
                start += source.arrayOffset();
            } else {
                array = new byte[length];
                source.get(array);
                start = 0;
            }
            synchronized (writeLock) {
                sendCount = networkSystem.sendDatagram(fd, array, start,
                        length, isa.getPort(), false, trafficClass, isa
                                .getAddress());
            }
        }
        source.position(oldposition + sendCount);
        return sendCount;
    } finally {
        end(sendCount >= 0);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:69,代码来源:DatagramChannelImpl.java


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