Package io.nodyn.fs

Source Code of io.nodyn.fs.UnsafeFs

package io.nodyn.fs;

import java.io.FileDescriptor;
import java.lang.reflect.Field;

/**
* @author Bob McWhirter
*/
public class UnsafeFs {

    public static FileDescriptor createFileDescriptor(int fd) throws IllegalAccessException, NoSuchFieldException {
        FileDescriptor fileDesc = new FileDescriptor();
        Field f = fileDesc.getClass().getDeclaredField("fd");
        f.setAccessible(true);
        f.setInt(fileDesc, fd );
        return fileDesc;
    }

    public static void dump(FileDescriptor fd) throws NoSuchFieldException, IllegalAccessException {

        Field f = fd.getClass().getDeclaredField("fd");
        f.setAccessible(true);
        System.err.println( "fd: " + f.getInt( fd ) );
        System.err.println( " - valid: " + fd.valid() );

        f = fd.getClass().getDeclaredField( "useCount" );
        f.setAccessible( true );
        System.err.println( " - count: " + f.get( fd ) );

        /*
        f = fd.getClass().getDeclaredField( "parent" );
        f.setAccessible( true );
        System.err.println( " - parent: " + f.get( fd ) );

        f = fd.getClass().getDeclaredField( "otherParents" );
        f.setAccessible( true );
        System.err.println( " - other: " + f.get( fd ) );
*/


    }
}
TOP

Related Classes of io.nodyn.fs.UnsafeFs

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.