Why is the java.io.FileDescriptor constructor open?

JavaDoc for java.io.FileDescriptor.FileDescriptor () says:

Creates an (invalid) FileDescriptor object.

If there is no purpose for the constructor, why is it an access level that is not declared as private-package?

+5
source share
2 answers

This constructor is publicly available because it is used externally java.io.

Classes using new FileDescriptor()in JRE 7u4 Linux x86:

java.io.FileInputStream
java.io.FileOutputStream
java.io.RandomAccessFile

java.lang.UNIXProcess
java.net.AbstractPlainDatagramSocketImpl
java.net.AbstractPlainSocketImpl
java.net.ServerSocket

sun.net.sdp.SdpSupport
sun.nio.ch.FileChannelImpl
sun.nio.ch.FileDispatcherImpl
sun.nio.ch.IOUtil
sun.nio.ch.PipeImpl
sun.nio.ch.SctpServerChannelImpl
sun.nio.ch.ServerSocketChannelImpl
sun.nio.ch.UnixAsynchronousServerSocketChannelImpl
sun.nio.fs.UnixChannelFactory

There is a method sun.misc.SharedSecretsthat allows the programmer to change the state FileDescriptorto valid (this fragment is found in java.io.FileDescriptor):

  static {
        sun.misc.SharedSecrets.setJavaIOFileDescriptorAccess(
            new sun.misc.JavaIOFileDescriptorAccess() {
                public void set(FileDescriptor obj, int fd) {
                    obj.fd = fd;
                }

                public int get(FileDescriptor obj) {
                    return obj.fd;
                }

                public void setHandle(FileDescriptor obj, long handle) {
                    obj.handle = handle;
                }

                public long getHandle(FileDescriptor obj) {
                    return obj.handle;
                }
            }
        );
    }

, , SharedSecrets (I.E. JRE), FileDescriptor FileDescriptor(). , JRE, .

+6

:

@since JDK1.0

, " Number , ", " ?" ..

, , @Deprecated , Java . Cruft , , Java , , Java.

-2

All Articles