Top Description Inners Fields Constructors Methods
org.apache.poi.poifs.nio

public final Class CleanerUtil

extends Object
Class Inheritance
Annotations
@SuppressForbidden:uses java.security features deprecated in java 17 - no other option though
Imports
org.apache.poi.util.ExceptionUtil, .SuppressForbidden, java.io.IOException, java.lang.invoke.MethodHandle, .MethodHandles, java.lang.reflect.Field, .Method, java.nio.ByteBuffer, java.security.AccessController, .PrivilegedAction, java.util.Objects

This is taken from Hadoop at https://issues.apache.org/jira/browse/HADOOP-12760 and https://github.com/apache/hadoop/blob/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/CleanerUtil.java Unfortunately this is not available in some general utility library yet, but hopefully will be at some point. sun.misc.Cleaner has moved in OpenJDK 9 and sun.misc.Unsafe#invokeCleaner(ByteBuffer) is the replacement. This class is a hack to use sun.misc.Cleaner in Java 8 and use the replacement in Java 9+. This implementation is inspired by LUCENE-6989.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
CleanerUtil.BufferCleaner

Pass in an implementation of this interface to cleanup ByteBuffers.

Field Summary

Modifier and TypeField and Description
private static final CleanerUtil.BufferCleaner
public static final String
UNMAP_NOT_SUPPORTED_REASON

if UNMAP_SUPPORTED is false, this contains the reason why unmapping is not supported.

public static final boolean
UNMAP_SUPPORTED

true, if this platform supports unmapping mmapped files.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static CleanerUtil.BufferCleaner

Returns:

null if not supported.
getCleaner
()

Reference to a BufferCleaner that does unmapping.

private static CleanerUtil.BufferCleaner
newBufferCleaner(final Class<?> unmappableBufferClass, final MethodHandle unmapper)

private static Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLEANERback to summary
private static final CleanerUtil.BufferCleaner CLEANER
UNMAP_NOT_SUPPORTED_REASONback to summary
public static final String UNMAP_NOT_SUPPORTED_REASON

if UNMAP_SUPPORTED is false, this contains the reason why unmapping is not supported.

UNMAP_SUPPORTEDback to summary
public static final boolean UNMAP_SUPPORTED

true, if this platform supports unmapping mmapped files.

Constructor Detail

CleanerUtilback to summary
private CleanerUtil()

Method Detail

getCleanerback to summary
public static CleanerUtil.BufferCleaner getCleaner()

Reference to a BufferCleaner that does unmapping.

Returns:CleanerUtil.BufferCleaner

null if not supported.

newBufferCleanerback to summary
private static CleanerUtil.BufferCleaner newBufferCleaner(final Class<?> unmappableBufferClass, final MethodHandle unmapper)
unmapHackImplback to summary
private static Object unmapHackImpl()
Annotations
@SuppressForbidden:Java 9 Jigsaw allows access to sun.misc.Cleaner, so setAccessible works
org.apache.poi.poifs.nio back to summary

public Interface CleanerUtil.BufferCleaner

Annotations
@FunctionalInterface

Pass in an implementation of this interface to cleanup ByteBuffers. CleanerUtil implements this to allow unmapping of bytebuffers with private Java APIs.

Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

freeBufferback to summary
public void freeBuffer(ByteBuffer b) throws IOException