FileDocCategorySizeDatePackage
AddressUtil.javaAPI DocAndroid 1.5 API3119Wed May 06 22:41:04 BST 2009org.apache.harmony.nio

AddressUtil

public class AddressUtil extends Object

Fields Summary
Constructors Summary
Methods Summary
public static intgetChannelAddress(java.nio.channels.Channel channel)
Gets the address of native resource held by the given channel, if has any. For network related channel, including SocketChannel, ServerSocketChannel and DatagramChannel, this method returns a int of Socket handler in Linux while returns a SOCKET (UINT_PTR) in windows. For FileChannel, this method returns the native file descriptor. For other channels, this method return 0, which means unsupported operation.

param
channel the given channel which may holds a native resource address
return
the address of native resource held by the given channel, if any, otherwise return 0

        if(channel instanceof FileDescriptorHandler){
            return getFDAddress(((FileDescriptorHandler) channel).getFD());    
        }else if(channel instanceof FileChannelImpl){
            return ((FileChannelImpl) channel).getHandle();    
        }
        return 0;
    
public static intgetDirectBufferAddress(java.nio.Buffer buf)
Gets the start address of a direct buffer.

This method corresponds to the JNI function:

void* GetDirectBufferAddress(JNIEnv* env, jobject buf);

param
buf the direct buffer whose address shall be returned must not be null.
return
the address of the buffer given, or zero if the buffer is not a direct Buffer.

        if (!(buf instanceof DirectBuffer)) {
            return 0;
        }
        return ((DirectBuffer) buf).getEffectiveAddress().toInt();
    
private static native intgetFDAddress(java.io.FileDescriptor fd)