You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
+13-14Lines changed: 13 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -137,6 +137,8 @@ public static Builder builder() {
137
137
138
138
privatefinalByteBufferbyteBuffer;
139
139
140
+
privatebooleanclean;
141
+
140
142
privatefinalFileChannelfileChannel;
141
143
142
144
@SuppressWarnings("resource")
@@ -209,26 +211,18 @@ public synchronized int available() throws IOException {
209
211
* disposed buffer. However, neither the bytes allocated to direct buffers nor file descriptors opened for memory-mapped buffers put pressure on the garbage
210
212
* collector. Waiting for garbage collection may lead to the depletion of off-heap memory or huge numbers of open files. There's unfortunately no standard
211
213
* API to manually dispose of these kinds of buffers.
212
-
*
213
-
* @param buffer the buffer to clean.
214
-
*/
215
-
privatevoidclean(finalByteBufferbuffer) {
216
-
if (buffer.isDirect()) {
217
-
cleanDirectBuffer(buffer);
218
-
}
219
-
}
220
-
221
-
/**
214
+
* <p>
222
215
* In Java 8, the type of {@code sun.nio.ch.DirectBuffer.cleaner()} was {@code sun.misc.Cleaner}, and it was possible to access the method
223
216
* {@code sun.misc.Cleaner.clean()} to invoke it. The type changed to {@code jdk.internal.ref.Cleaner} in later JDKs, and the {@code clean()} method is not
224
217
* accessible even with reflection. However {@code sun.misc.Unsafe} added an {@code invokeCleaner()} method in JDK 9+ and this is still accessible with
225
218
* reflection.
226
-
*
227
-
* @param buffer the buffer to clean. must be a DirectBuffer.
* Tests that the {@code clean(ByteBuffer)} method only performs buffer cleaning once, even when {@link BufferedFileChannelInputStream#close()} is invoked
72
+
* multiple times. The private {@code clean} boolean field is inspected via reflection: it must be {@code false} before any close, {@code true} after the
73
+
* first close, and remain {@code true} after a second close, confirming that {@code ByteBufferCleaner.clean()} is never called more than once.
0 commit comments