Top Description Fields Constructors Methods
org.lwjgl.system

pack-priv final Class SharedLibraryLoader

extends Object
Class Inheritance
Imports
org.lwjgl.*, javax.annotation.*, javax.annotation.concurrent.*, java.io.*, java.net.*, java.nio.channels.*, java.nio.file.*, java.util.*, java.util.concurrent.locks.*, java.util.function.*, java.util.stream.*, java.util.zip.*

Loads shared libraries and native resources from the classpath.

The libraries may be packed in JAR files, in which case they will be extracted to a temporary directory and that directory will be prepended to Configuration#LIBRARY_PATH.

Authors
Mario Zechner (https://github.com/badlogic), Nathan Sweet (https://github.com/NathanSweet)
See Also
Configuration#SHARED_LIBRARY_EXTRACT_DIRECTORY, Configuration#SHARED_LIBRARY_EXTRACT_PATH

Field Summary

Modifier and TypeField and Description
private static boolean
private static final Lock
private static Path
private static HashSet<Path>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static boolean

Returns:

true if the file is writable
canWrite
(Path root, Path
the file to test
file
,
URL resource, Consumer<String> load)

Returns true if the parent directories of the file can be created and the file can be written.

private static void
private static long

Returns:

the CRC
crc
(InputStream
the stream
input
)

Returns a CRC of the remaining bytes in a stream.

private static FileChannel

Returns:

a FileChannel that has locked the resource
extract
(Path
the extracted file
file
,
URL
the resource to extract
resource
)

Extracts a native library resource if it does not already exist or the CRC does not match.

private static Path

Returns:

the extracted library
getExtractPath
(String
the resource filename
filename
,
URL resource, Consumer<String> load)

Returns a path to a file that can be written.

private static void
initExtractPath(Path extractPath)

pack-priv static FileChannel

Returns:

a FileChannel that has locked the resource file
load
(String
the resource name
name
,
String
the resource filename
filename
,
URL
the classpath URL were the resource can be found
resource
,
Consumer<String>
should call System::load in the context of the appropriate ClassLoader
load
)

Extracts the specified shared library or native resource from the classpath to a temporary directory.

private static FileChannel
lock(Path
the file to lock
file
)

Locks a file.

private static void
workaroundJDK8195129(Path file, URL resource, Consumer<String> load)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

checkedJDK8195129back to summary
private static boolean checkedJDK8195129
EXTRACT_PATH_LOCKback to summary
private static final Lock EXTRACT_PATH_LOCK
extractPathback to summary
private static Path extractPath
Annotations
@GuardedBy:EXTRACT_PATH_LOCK
@Nullable
extractPathsback to summary
private static HashSet<Path> extractPaths

Constructor Detail

SharedLibraryLoaderback to summary
private SharedLibraryLoader()

Method Detail

canWriteback to summary
private static boolean canWrite(Path root, Path file, URL resource, Consumer<String> load)

Returns true if the parent directories of the file can be created and the file can be written.

Parameters
file:Path

the file to test

Returns:boolean

true if the file is writable

canWriteCleanupback to summary
private static void canWriteCleanup(Path root, Path file)
crcback to summary
private static long crc(InputStream input) throws IOException

Returns a CRC of the remaining bytes in a stream.

Parameters
input:InputStream

the stream

Returns:long

the CRC

extractback to summary
private static FileChannel extract(Path file, URL resource) throws IOException

Extracts a native library resource if it does not already exist or the CRC does not match.

Parameters
file:Path

the extracted file

resource:URL

the resource to extract

Returns:FileChannel

a FileChannel that has locked the resource

Exceptions
IOException:
if an IO error occurs
getExtractPathback to summary
private static Path getExtractPath(String filename, URL resource, Consumer<String> load)

Returns a path to a file that can be written. Tries multiple locations and verifies writing succeeds.

Parameters
filename:String

the resource filename

Returns:Path

the extracted library

initExtractPathback to summary
private static void initExtractPath(Path extractPath)
loadback to summary
pack-priv static FileChannel load(String name, String filename, URL resource, Consumer<String> load)

Extracts the specified shared library or native resource from the classpath to a temporary directory.

Parameters
name:String

the resource name

filename:String

the resource filename

resource:URL

the classpath URL were the resource can be found

load:Consumer<String>

should call System::load in the context of the appropriate ClassLoader

Returns:FileChannel

a FileChannel that has locked the resource file

lockback to summary
private static FileChannel lock(Path file)

Locks a file.

Parameters
file:Path

the file to lock

workaroundJDK8195129back to summary
private static void workaroundJDK8195129(Path file, URL resource, Consumer<String> load) throws Throwable