• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AddressUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



AddressUtil类属于org.apache.harmony.nio包,在下文中一共展示了AddressUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: decodeLoop

import org.apache.harmony.nio.AddressUtil; //导入依赖的package包/类
protected CoderResult decodeLoop(ByteBuffer bb, CharBuffer cb){
                  int cbRemaining = cb.remaining();
                  if(CharsetProviderImpl.hasLoadedNatives() && bb.isDirect() && bb.hasRemaining() && cb.hasArray()){
                      int cbPos = cb.position();
                      int bbPos = bb.position();
                      int[] res = {bb.remaining(), cbRemaining, 0, 0};
                      nDecode(cb.array(), cb.arrayOffset()+cbPos, bb.remaining(), AddressUtil.getDirectBufferAddress(bb), bbPos, res);
                      bb.position(bbPos+bb.remaining()-res[0]);
                      cb.position(cbPos+cbRemaining-res[1]);
                      if( res[2] != 0 ) {
                          return CoderResult.unmappableForLength(res[2]);
                      } else {
                          if(res[3]!=0) return CoderResult.OVERFLOW;
                      }
                  }else{
                          while(bb.hasRemaining()){
                              if( cbRemaining == 0 ) return CoderResult.OVERFLOW;
                              int in = (int)bb.get();
                              if(in < 0 && in >= -114){
                                  int index = decodeIndex[in&0xFF];
                                  if(index < 0 && arrDecode0.charAt(in&0xFF) == '\u0000' || !bb.hasRemaining()) {
                                      if(arrDecode0.charAt(in&0xFF) == '\u0000') {
                                          bb.position(bb.position() - 1);
                                          if(index > 0 && bb.remaining()==1) {
                                              return CoderResult.UNDERFLOW;
                                          }
                                          return CoderResult.unmappableForLength(1);
                                      } else { 
                                          cb.put(arrDecode0.charAt(in&0xFF));
                                          return CoderResult.UNDERFLOW;
                                      }
                                  }
                                  int variable = 0;
                                  byte b2 = 0;
                                  if (index < 0) { variable = 0; index = in&0xFF; } else{
                                      variable = index >> 4;
                                      index <<= 8;
                                      b2 = bb.get();
                                      index += (b2 & 0xFF);
                                      index = index - (variable << 12);
                                  }
                                  char resultChar = '\u0000';
                                  switch(variable) {
                                          case 0:
                                            resultChar = arrDecode0.charAt(index);
                                            break;
                                          case 1:
                                            resultChar = arrDecode1.charAt(index);
                                            break;
                                          case 2:
                                            resultChar = arrDecode2.charAt(index);
                                            break;
                                          case 3:
                                            resultChar = arrDecode3.charAt(index);
                                            break;
                                          case 4:
                                            resultChar = arrDecode4.charAt(index);
                                            break;
                                          case 5:
                                            resultChar = arrDecode5.charAt(index);
                                            break;
                                  }
                                  if (resultChar != '\u0000') {
                                      cb.put(resultChar);
                                  } else {
                                      bb.position(bb.position() - 2);
                                      if(arrDecode0.charAt(b2 & 0xFF) == '\u0000') {
                                          return CoderResult.unmappableForLength(2);
                                      } else {
                                          return CoderResult.unmappableForLength(1);
                                      }
                                  }
                              }else {
                                  cb.put((char)(in & 0xFF));
                              }
                              cbRemaining--;
                          }
	} 
                      return CoderResult.UNDERFLOW;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:81,代码来源:EUC_KR.java


示例12: decodeLoop

import org.apache.harmony.nio.AddressUtil; //导入依赖的package包/类
protected CoderResult decodeLoop(ByteBuffer bb, CharBuffer cb){
                  int cbRemaining = cb.remaining();
                  if(CharsetProviderImpl.hasLoadedNatives() && bb.isDirect() && bb.hasRemaining() && cb.hasArray()){
                      int cbPos = cb.position();
                      int bbPos = bb.position();
                      int[] res = {bb.remaining(), cbRemaining, 0, 0};
                      nDecode(cb.array(), cb.arrayOffset()+cbPos, bb.remaining(), AddressUtil.getDirectBufferAddress(bb), bbPos, res);
                      bb.position(bbPos+bb.remaining()-res[0]);
                      cb.position(cbPos+cbRemaining-res[1]);
                      if( res[2] != 0 ) {
                          return CoderResult.unmappableForLength(res[2]);
                      } else {
                          if(res[3]!=0) return CoderResult.OVERFLOW;
                      }
                  }else{
                          while(bb.hasRemaining()){
                              if( cbRemaining == 0 ) return CoderResult.OVERFLOW;
                              char in = (char)(bb.get() & 0xFF);
                              if(in >= 26){
                                  int index = decodeIndex[in&0xFF];
                                  if(index < 0 && arrDecode0.charAt(in&0xFF) == '\u0000' || !bb.hasRemaining()) {
                                      if(arrDecode0.charAt(in&0xFF) == '\u0000') {
                                          bb.position(bb.position() - 1);
                                          if(index > 0 && bb.remaining()==1) {
                                              return CoderResult.UNDERFLOW;
                                          }
                                          return CoderResult.unmappableForLength(1);
                                      } else { 
                                          cb.put(arrDecode0.charAt(in&0xFF));
                                          return CoderResult.UNDERFLOW;
                                      }
                                  }
                                  int variable = 0;
                                  byte b2 = 0;
                                  if (index < 0) { variable = 0; index = in&0xFF; } else{
                                      variable = index >> 4;
                                      index <<= 8;
                                      b2 = bb.get();
                                      index += (b2 & 0xFF);
                                      index = index - (variable << 12);
                                  }
                                  char resultChar = '\u0000';
                                  switch(variable) {
                                          case 0:
                                            resultChar = arrDecode0.charAt(index);
                                            break;
                                          case 1:
                                            resultChar = arrDecode1.charAt(index);
                                            break;
                                          case 2:
                                            resultChar = arrDecode2.charAt(index);
                                            break;
                                          case 3:
                                            resultChar = arrDecode3.charAt(index);
                                            break;
                                  }
                                  if (resultChar != '\u0000') {
                                      cb.put(resultChar);
                                  } else {
                                      bb.position(bb.position() - 2);
                                      if(arrDecode0.charAt(b2 & 0xFF) == '\u0000') {
                                          return CoderResult.unmappableForLength(2);
                                      } else {
                                          return CoderResult.unmappableForLength(1);
                                      }
                                  }
                              }else {
                                  cb.put((char)(in & 0xFF));
                              }
                              cbRemaining--;
                          }
	} 
                      return CoderResult.UNDERFLOW;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:75,代码来源:windows_31j.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:shannah,项目名称:cn1,代码行数:43,代码来源:DatagramChannelImpl.java


示例14: 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


示例15: test_getDirectBufferAddress

import org.apache.harmony.nio.AddressUtil; //导入依赖的package包/类
/**
 * @tests AddressUtil#getDirectBufferAddress
 */
public void test_getDirectBufferAddress() throws Exception {
    ByteBuffer buf = ByteBuffer.allocateDirect(10);
    assertTrue(AddressUtil.getDirectBufferAddress(buf) != 0);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:8,代码来源:AddressUtilTest.java


示例16: test_getSocketChannelAddress

import org.apache.harmony.nio.AddressUtil; //导入依赖的package包/类
/**
 * @tests AddressUtil#getChannelAddress
 */
public void test_getSocketChannelAddress() throws Exception {
    SocketChannel sc = SocketChannel.open();
    assertTrue(AddressUtil.getChannelAddress(sc)>0);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:8,代码来源:AddressUtilTest.java


示例17: test_getDatagramChannelAddress

import org.apache.harmony.nio.AddressUtil; //导入依赖的package包/类
/**
 * @tests AddressUtil#getChannelAddress
 */
public void test_getDatagramChannelAddress() throws Exception {
    DatagramChannel dc = DatagramChannel.open();
    assertTrue(AddressUtil.getChannelAddress(dc)>0);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:8,代码来源:AddressUtilTest.java


示例18: test_getServerSocketChannelAddress

import org.apache.harmony.nio.AddressUtil; //导入依赖的package包/类
/**
 * @tests AddressUtil#getChannelAddress
 */
public void test_getServerSocketChannelAddress() throws Exception {
    ServerSocketChannel ssc = ServerSocketChannel.open();
    assertTrue(AddressUtil.getChannelAddress(ssc)>0);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:8,代码来源:AddressUtilTest.java


示例19: test_getNonNativeChannelAddress

import org.apache.harmony.nio.AddressUtil; //导入依赖的package包/类
/**
 * @tests AddressUtil#getChannelAddress
 */
public void test_getNonNativeChannelAddress() throws Exception{
    Channel channel = new MockChannel();
    assertEquals(0, AddressUtil.getChannelAddress(channel));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:8,代码来源:AddressUtilTest.java


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JavaRunConfigurationModule类代码示例发布时间:2022-05-22
下一篇:
Java AndroidClock类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap