Class FileDescriptor

  • Direct Known Subclasses:
    Socket

    public class FileDescriptor
    extends java.lang.Object
    Native FileDescriptor implementation which allows to wrap an int and provide a FileDescriptor for it.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileDescriptor​(int fd)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) boolean casState​(int expected, int update)  
      void close()
      Close the file descriptor.
      private static int close​(int fd)  
      boolean equals​(java.lang.Object o)  
      static FileDescriptor from​(java.io.File file)
      Open a new FileDescriptor for the given File.
      static FileDescriptor from​(java.lang.String path)
      Open a new FileDescriptor for the given path.
      int hashCode()  
      (package private) static int inputShutdown​(int state)  
      int intValue()
      Return the int value of the filedescriptor.
      (package private) static boolean isClosed​(int state)  
      (package private) static boolean isInputShutdown​(int state)  
      boolean isOpen()
      Returns true if the file descriptor is open.
      (package private) static boolean isOutputShutdown​(int state)  
      protected boolean markClosed()  
      private static long newPipe()  
      private static int open​(java.lang.String path)  
      (package private) static int outputShutdown​(int state)  
      static FileDescriptor[] pipe()  
      private static int read​(int fd, java.nio.ByteBuffer buf, int pos, int limit)  
      int read​(java.nio.ByteBuffer buf, int pos, int limit)  
      private static int readAddress​(int fd, long address, int pos, int limit)  
      int readAddress​(long address, int pos, int limit)  
      java.lang.String toString()  
      private static int write​(int fd, java.nio.ByteBuffer buf, int pos, int limit)  
      int write​(java.nio.ByteBuffer buf, int pos, int limit)  
      private static int writeAddress​(int fd, long address, int pos, int limit)  
      int writeAddress​(long address, int pos, int limit)  
      private static long writev​(int fd, java.nio.ByteBuffer[] buffers, int offset, int length, long maxBytesToWrite)  
      long writev​(java.nio.ByteBuffer[] buffers, int offset, int length, long maxBytesToWrite)  
      private static long writevAddresses​(int fd, long memoryAddress, int length)  
      long writevAddresses​(long memoryAddress, int length)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • stateUpdater

        private static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<FileDescriptor> stateUpdater
      • STATE_INPUT_SHUTDOWN_MASK

        private static final int STATE_INPUT_SHUTDOWN_MASK
        See Also:
        Constant Field Values
      • STATE_OUTPUT_SHUTDOWN_MASK

        private static final int STATE_OUTPUT_SHUTDOWN_MASK
        See Also:
        Constant Field Values
      • state

        volatile int state
        Bit map = [Output Shutdown | Input Shutdown | Closed]
      • fd

        final int fd
    • Constructor Detail

      • FileDescriptor

        public FileDescriptor​(int fd)
    • Method Detail

      • intValue

        public final int intValue()
        Return the int value of the filedescriptor.
      • markClosed

        protected boolean markClosed()
      • close

        public void close()
                   throws java.io.IOException
        Close the file descriptor.
        Throws:
        java.io.IOException
      • isOpen

        public boolean isOpen()
        Returns true if the file descriptor is open.
      • write

        public final int write​(java.nio.ByteBuffer buf,
                               int pos,
                               int limit)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeAddress

        public final int writeAddress​(long address,
                                      int pos,
                                      int limit)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writev

        public final long writev​(java.nio.ByteBuffer[] buffers,
                                 int offset,
                                 int length,
                                 long maxBytesToWrite)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writevAddresses

        public final long writevAddresses​(long memoryAddress,
                                          int length)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public final int read​(java.nio.ByteBuffer buf,
                              int pos,
                              int limit)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readAddress

        public final int readAddress​(long address,
                                     int pos,
                                     int limit)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • from

        public static FileDescriptor from​(java.lang.String path)
                                   throws java.io.IOException
        Open a new FileDescriptor for the given path.
        Throws:
        java.io.IOException
      • from

        public static FileDescriptor from​(java.io.File file)
                                   throws java.io.IOException
        Open a new FileDescriptor for the given File.
        Throws:
        java.io.IOException
      • pipe

        public static FileDescriptor[] pipe()
                                     throws java.io.IOException
        Returns:
        [0] = read end, [1] = write end
        Throws:
        java.io.IOException
      • casState

        final boolean casState​(int expected,
                               int update)
      • isClosed

        static boolean isClosed​(int state)
      • isInputShutdown

        static boolean isInputShutdown​(int state)
      • isOutputShutdown

        static boolean isOutputShutdown​(int state)
      • inputShutdown

        static int inputShutdown​(int state)
      • outputShutdown

        static int outputShutdown​(int state)
      • open

        private static int open​(java.lang.String path)
      • close

        private static int close​(int fd)
      • write

        private static int write​(int fd,
                                 java.nio.ByteBuffer buf,
                                 int pos,
                                 int limit)
      • writeAddress

        private static int writeAddress​(int fd,
                                        long address,
                                        int pos,
                                        int limit)
      • writev

        private static long writev​(int fd,
                                   java.nio.ByteBuffer[] buffers,
                                   int offset,
                                   int length,
                                   long maxBytesToWrite)
      • writevAddresses

        private static long writevAddresses​(int fd,
                                            long memoryAddress,
                                            int length)
      • read

        private static int read​(int fd,
                                java.nio.ByteBuffer buf,
                                int pos,
                                int limit)
      • readAddress

        private static int readAddress​(int fd,
                                       long address,
                                       int pos,
                                       int limit)
      • newPipe

        private static long newPipe()