src/java.base/unix/classes/sun/nio/ch/FileKey.java

Print this page
rev 11066 : 8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
Summary: FileKey.create() should throw an IOException directly instead of wrapping it in an Error.
Reviewed-by: TBD


  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.nio.ch;
  27 
  28 import java.io.FileDescriptor;
  29 import java.io.IOException;
  30 
  31 /*
  32  * Represents a key to a specific file on Solaris or Linux
  33  */
  34 public class FileKey {
  35 
  36     private long st_dev;    // ID of device
  37     private long st_ino;    // Inode number
  38 
  39     private FileKey() { }
  40 
  41     public static FileKey create(FileDescriptor fd) {
  42         FileKey fk = new FileKey();
  43         try {
  44             fk.init(fd);
  45         } catch (IOException ioe) {
  46             throw new Error(ioe);
  47         }
  48         return fk;
  49     }
  50 
  51     public int hashCode() {
  52         return (int)(st_dev ^ (st_dev >>> 32)) +
  53                (int)(st_ino ^ (st_ino >>> 32));
  54     }
  55 
  56     public boolean equals(Object obj) {
  57         if (obj == this)
  58             return true;
  59         if (!(obj instanceof FileKey))
  60             return false;
  61         FileKey other = (FileKey)obj;
  62         if ((this.st_dev != other.st_dev) ||
  63             (this.st_ino != other.st_ino)) {
  64             return false;
  65         }
  66         return true;
  67     }


  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.nio.ch;
  27 
  28 import java.io.FileDescriptor;
  29 import java.io.IOException;
  30 
  31 /*
  32  * Represents a key to a specific file on Solaris or Linux
  33  */
  34 public class FileKey {
  35 
  36     private long st_dev;    // ID of device
  37     private long st_ino;    // Inode number
  38 
  39     private FileKey() { }
  40 
  41     public static FileKey create(FileDescriptor fd) throws IOException {
  42         FileKey fk = new FileKey();

  43         fk.init(fd);



  44         return fk;
  45     }
  46 
  47     public int hashCode() {
  48         return (int)(st_dev ^ (st_dev >>> 32)) +
  49                (int)(st_ino ^ (st_ino >>> 32));
  50     }
  51 
  52     public boolean equals(Object obj) {
  53         if (obj == this)
  54             return true;
  55         if (!(obj instanceof FileKey))
  56             return false;
  57         FileKey other = (FileKey)obj;
  58         if ((this.st_dev != other.st_dev) ||
  59             (this.st_ino != other.st_ino)) {
  60             return false;
  61         }
  62         return true;
  63     }