Class FileDescriptor

java.lang.Object
io.netty.channel.unix.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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final int
     
    (package private) int
    Bit map = [Output Shutdown | Input Shutdown | Closed]
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<FileDescriptor>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

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

    Methods inherited from class java.lang.Object

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

    • stateUpdater

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

      private static final int STATE_CLOSED_MASK
      See Also:
    • STATE_INPUT_SHUTDOWN_MASK

      private static final int STATE_INPUT_SHUTDOWN_MASK
      See Also:
    • STATE_OUTPUT_SHUTDOWN_MASK

      private static final int STATE_OUTPUT_SHUTDOWN_MASK
      See Also:
    • STATE_ALL_MASK

      private static final int STATE_ALL_MASK
      See Also:
    • state

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

      final int fd
  • Constructor Details

    • FileDescriptor

      public FileDescriptor(int fd)
  • Method Details

    • 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, write-only.

      WARNING: if path already exists it is truncated to zero length; if it does not exist it is created with mode 0666 &amp; ~umask. Do not pass untrusted or externally-derived paths to this method.

      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, write-only.

      WARNING: see from(String): an existing file is truncated and a missing one is created.

      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()