equal
deleted
inserted
replaced
88 private volatile boolean uninterruptible; |
88 private volatile boolean uninterruptible; |
89 |
89 |
90 // Cleanable with an action which closes this channel's file descriptor |
90 // Cleanable with an action which closes this channel's file descriptor |
91 private final Cleanable closer; |
91 private final Cleanable closer; |
92 |
92 |
|
93 private static class Closer implements Runnable { |
|
94 private final FileDescriptor fd; |
|
95 |
|
96 Closer(FileDescriptor fd) { |
|
97 this.fd = fd; |
|
98 } |
|
99 |
|
100 public void run() { |
|
101 fdAccess.close(fd); |
|
102 } |
|
103 } |
|
104 |
93 private FileChannelImpl(FileDescriptor fd, String path, boolean readable, |
105 private FileChannelImpl(FileDescriptor fd, String path, boolean readable, |
94 boolean writable, Object parent) |
106 boolean writable, Object parent) |
95 { |
107 { |
96 this.fd = fd; |
108 this.fd = fd; |
97 this.readable = readable; |
109 this.readable = readable; |
99 this.parent = parent; |
111 this.parent = parent; |
100 this.path = path; |
112 this.path = path; |
101 this.nd = new FileDispatcherImpl(); |
113 this.nd = new FileDispatcherImpl(); |
102 // Register a cleaning action if and only if there is no parent |
114 // Register a cleaning action if and only if there is no parent |
103 // as the parent will take care of closing the file descriptor. |
115 // as the parent will take care of closing the file descriptor. |
104 this.closer= parent != null ? null : |
116 // FileChannel is used by the LambdaMetaFactory so a lambda cannot |
105 CleanerFactory.cleaner().register(this, () -> fdAccess.close(fd)); |
117 // be used here hence we use a nested class instead. |
|
118 this.closer = parent != null ? null : |
|
119 CleanerFactory.cleaner().register(this, new Closer(fd)); |
106 } |
120 } |
107 |
121 |
108 // Used by FileInputStream.getChannel(), FileOutputStream.getChannel |
122 // Used by FileInputStream.getChannel(), FileOutputStream.getChannel |
109 // and RandomAccessFile.getChannel() |
123 // and RandomAccessFile.getChannel() |
110 public static FileChannel open(FileDescriptor fd, String path, |
124 public static FileChannel open(FileDescriptor fd, String path, |