Example usage for java.io FileDescriptor getClass

List of usage examples for java.io FileDescriptor getClass

Introduction

In this page you can find the example usage for java.io FileDescriptor getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static int getFd(FileDescriptor fileDescriptor) {
    int fdInt = -1;
    try {/*from   w  w  w.  jav  a  2s  .co  m*/
        if (fileDescriptor != null) {
            Field descriptor = fileDescriptor.getClass().getDeclaredField("descriptor");
            descriptor.setAccessible(true);
            fdInt = descriptor.getInt(fileDescriptor);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return fdInt;
}

From source file:org.apache.cassandra.utils.CLibrary.java

/**
 * Get system file descriptor from FileDescriptor object.
 * @param descriptor - FileDescriptor objec to get fd from
 * @return file descriptor, -1 or error/*from   w  w w . ja  v  a2  s .c om*/
 */
public static int getfd(FileDescriptor descriptor) {
    Field field = FBUtilities.getProtectedField(descriptor.getClass(), "fd");

    if (field == null)
        return -1;

    try {
        return field.getInt(descriptor);
    } catch (Exception e) {
        logger.warn("unable to read fd field from FileDescriptor");
    }

    return -1;
}