Package com.kenai.jffi.internal
Class StubLoader
- java.lang.Object
-
- com.kenai.jffi.internal.StubLoader
-
public class StubLoader extends java.lang.Object
Loads the native stub library. This is intended to only ever be called reflectively, so it cannot access other jffi classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StubLoader.CPU
The common names of cpu architectures.static class
StubLoader.OS
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
bootLibraryPropertyName
private static java.lang.String
bootPropertyFilename
private static StubLoader.CPU
cpu
private static java.lang.Throwable
failureCause
private static java.lang.String
JFFI_EXTRACT_DIR
private static java.lang.String
JFFI_EXTRACT_NAME
private static java.io.File
jffiExtractDir
private static java.lang.String
jffiExtractName
private static boolean
loaded
private static java.util.Locale
LOCALE
private static StubLoader.OS
os
private static java.lang.String
stubLibraryName
private static java.lang.String
TMPDIR
private static java.lang.String
TMPDIR_ENV
static java.lang.String
TMPDIR_EXEC_ERROR
private static java.lang.String
TMPDIR_RECOMMENDATION
static java.lang.String
TMPDIR_WRITE_ERROR
static int
VERSION_MAJOR
static int
VERSION_MINOR
private static java.lang.String
versionClassName
-
Constructor Summary
Constructors Constructor Description StubLoader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.io.File
calculateExtractPath(java.io.File tmpDirFile)
(package private) static java.io.File
calculateExtractPath(java.io.File tmpDirFile, java.lang.String jffiExtractName)
private static StubLoader.CPU
determineCPU()
Determines the CPU architecture the JVM is running on.private static StubLoader.OS
determineOS()
Determines the operating system jffi is running onprivate static java.lang.SecurityException
digestMismatchError(java.io.File dstFile)
(package private) static java.lang.String
dlExtension()
private static java.lang.String
getAlternateLibraryPath(java.lang.String path)
private static java.lang.String
getBootPath()
static StubLoader.CPU
getCPU()
static java.lang.Throwable
getFailureCause()
static StubLoader.OS
getOS()
static java.lang.String
getPlatformName()
Gets the name of thisPlatform
.private static java.io.InputStream
getResourceAsStream(java.lang.String resourceName)
private static java.lang.String
getStubLibraryName()
Gets the name of the stub library.private static java.lang.String
getStubLibraryPath()
Gets the path within the jar file of the stub native library.private static java.io.InputStream
getStubLibraryStream()
Gets anInputStream
representing the stub library image stored in the jar file.private static int
getVersionField(java.lang.String name)
static boolean
isLoaded()
(package private) static void
load()
Loads the stub libraryprivate static boolean
loadFromBootPath(java.lang.String libName, java.lang.String bootPath, java.util.Collection<java.lang.Throwable> errors)
private static void
loadFromJar(java.io.File tmpDirFile)
private static java.lang.SecurityException
sizeMismatchError(java.io.File dstFile, int sourceSize, int targetSize)
private static java.lang.UnsatisfiedLinkError
tempLoadError(java.lang.UnsatisfiedLinkError ule)
private static java.io.IOException
tempReadonlyError(java.io.IOException ioe)
private static void
unpackLibrary(java.io.File dstFile, java.io.InputStream sourceIS)
private static void
verifyExistingLibrary(java.io.File dstFile, java.io.InputStream sourceIS)
-
-
-
Field Detail
-
VERSION_MAJOR
public static final int VERSION_MAJOR
-
VERSION_MINOR
public static final int VERSION_MINOR
-
versionClassName
private static final java.lang.String versionClassName
- See Also:
- Constant Field Values
-
LOCALE
private static final java.util.Locale LOCALE
-
bootPropertyFilename
private static final java.lang.String bootPropertyFilename
- See Also:
- Constant Field Values
-
bootLibraryPropertyName
private static final java.lang.String bootLibraryPropertyName
- See Also:
- Constant Field Values
-
stubLibraryName
private static final java.lang.String stubLibraryName
-
TMPDIR_ENV
private static final java.lang.String TMPDIR_ENV
-
TMPDIR
private static final java.lang.String TMPDIR
-
TMPDIR_RECOMMENDATION
private static final java.lang.String TMPDIR_RECOMMENDATION
-
TMPDIR_WRITE_ERROR
public static final java.lang.String TMPDIR_WRITE_ERROR
-
TMPDIR_EXEC_ERROR
public static final java.lang.String TMPDIR_EXEC_ERROR
-
os
private static volatile StubLoader.OS os
-
cpu
private static volatile StubLoader.CPU cpu
-
failureCause
private static volatile java.lang.Throwable failureCause
-
loaded
private static volatile boolean loaded
-
jffiExtractDir
private static final java.io.File jffiExtractDir
-
jffiExtractName
private static final java.lang.String jffiExtractName
-
JFFI_EXTRACT_DIR
private static final java.lang.String JFFI_EXTRACT_DIR
- See Also:
- Constant Field Values
-
JFFI_EXTRACT_NAME
private static final java.lang.String JFFI_EXTRACT_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
isLoaded
public static final boolean isLoaded()
-
getFailureCause
public static final java.lang.Throwable getFailureCause()
-
determineOS
private static StubLoader.OS determineOS()
Determines the operating system jffi is running on- Returns:
- An member of the
OS
enum.
-
determineCPU
private static StubLoader.CPU determineCPU()
Determines the CPU architecture the JVM is running on. This normalizes all the variations that are equivalent (e.g. i386, x86, i86pc) into a common cpu type.- Returns:
- A member of the
CPU
enum.
-
getCPU
public static StubLoader.CPU getCPU()
-
getOS
public static StubLoader.OS getOS()
-
getStubLibraryName
private static java.lang.String getStubLibraryName()
Gets the name of the stub library.- Returns:
- The name of the stub library as a
String
-
getPlatformName
public static java.lang.String getPlatformName()
Gets the name of thisPlatform
.- Returns:
- The name of this platform.
-
getStubLibraryPath
private static java.lang.String getStubLibraryPath()
Gets the path within the jar file of the stub native library.- Returns:
- The path of the jar file.
-
load
static void load()
Loads the stub library
-
getBootPath
private static java.lang.String getBootPath()
-
getAlternateLibraryPath
private static java.lang.String getAlternateLibraryPath(java.lang.String path)
-
loadFromBootPath
private static boolean loadFromBootPath(java.lang.String libName, java.lang.String bootPath, java.util.Collection<java.lang.Throwable> errors)
-
dlExtension
static java.lang.String dlExtension()
-
loadFromJar
private static void loadFromJar(java.io.File tmpDirFile) throws java.io.IOException, java.lang.LinkageError
- Throws:
java.io.IOException
java.lang.LinkageError
-
unpackLibrary
private static void unpackLibrary(java.io.File dstFile, java.io.InputStream sourceIS) throws java.io.IOException
- Throws:
java.io.IOException
-
verifyExistingLibrary
private static void verifyExistingLibrary(java.io.File dstFile, java.io.InputStream sourceIS) throws java.io.IOException
- Throws:
java.io.IOException
-
sizeMismatchError
private static java.lang.SecurityException sizeMismatchError(java.io.File dstFile, int sourceSize, int targetSize)
-
digestMismatchError
private static java.lang.SecurityException digestMismatchError(java.io.File dstFile)
-
calculateExtractPath
static java.io.File calculateExtractPath(java.io.File tmpDirFile, java.lang.String jffiExtractName) throws java.io.IOException
- Throws:
java.io.IOException
-
calculateExtractPath
static java.io.File calculateExtractPath(java.io.File tmpDirFile) throws java.io.IOException
- Throws:
java.io.IOException
-
tempReadonlyError
private static java.io.IOException tempReadonlyError(java.io.IOException ioe)
-
tempLoadError
private static java.lang.UnsatisfiedLinkError tempLoadError(java.lang.UnsatisfiedLinkError ule)
-
getStubLibraryStream
private static java.io.InputStream getStubLibraryStream()
Gets anInputStream
representing the stub library image stored in the jar file.- Returns:
- A new
InputStream
-
getResourceAsStream
private static java.io.InputStream getResourceAsStream(java.lang.String resourceName)
-
getVersionField
private static int getVersionField(java.lang.String name)
-
-