Top Description Fields Constructors Methods
com.badlogic.gdx.utils

public Class SharedLibraryLoader

extends Object
Class Inheritance
Imports
java.io.Closeable, .File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .IOException, .InputStream, java.lang.reflect.Method, java.util.HashSet, .Random, .UUID, java.util.zip.CRC32, .ZipEntry, .ZipFile

Loads shared libraries from a natives jar file (desktop) or arm folders (Android). For desktop projects, have the natives jar in the classpath, for Android projects put the shared libraries in the libs/armeabi and libs/armeabi-v7a folders.
Authors
mzechner, Nathan Sweet

Field Summary

Modifier and TypeField and Description
public static Architecture
public static Architecture.Bitness
public static boolean
is64Bit

Deprecated Use bitness as SharedLibraryLoader.bitness == Architecture.Bitness._64 instead.
public static boolean
isAndroid

Deprecated Use os as SharedLibraryLoader.os == Os.Android instead.
public static boolean
isARM

Deprecated Use architecture as SharedLibraryLoader.architecture == Architecture.ARM instead.
public static boolean
isIos

Deprecated Use os as SharedLibraryLoader.os == Os.IOS instead.
public static boolean
isLinux

Deprecated Use os as SharedLibraryLoader.os == Os.Linux instead.
public static boolean
isMac

Deprecated Use os as SharedLibraryLoader.os == Os.MacOsX instead.
public static boolean
isWindows

Deprecated Use os as SharedLibraryLoader.os == Os.Windows instead.
private static final HashSet<String>
private String
public static Os
private static final Random

Constructor Summary

AccessConstructor and Description
public
public
SharedLibraryLoader(String nativesJar)

Fetches the natives from the given natives jar file.

Method Summary

Modifier and TypeMethod and Description
private boolean
private boolean
canWrite(File file)

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

public static void
public String
crc(InputStream input)

Returns a CRC of the remaining bytes in the stream.

public File

Returns:

The extracted file.
extractFile
(String
The file to extract from the classpath or JAR.
sourcePath
,
String
The name of the subdirectory where the file will be extracted. If null, the file's CRC will be used.
dirName
)

Extracts the specified file to the specified directory if it does not already exist or the CRC does not match.

private File
extractFile(String sourcePath, String sourceCrc, File extractedFile)

public void
extractFileTo(String
The file to extract from the classpath or JAR.
sourcePath
,
File
The location where the extracted file will be written.
dir
)

Extracts the specified file into the temp directory if it does not already exist or the CRC does not match.

private File

Returns:

null if a writable path could not be found.
getExtractedFile
(String dirName, String fileName)

Returns a path to a file that can be written.

public static synchronized boolean
isLoaded(String libraryName)

public void
load(String
The platform independent library name. If not contain a prefix (eg lib) or suffix (eg .dll).
libraryName
)

Loads a shared library for the platform the application is running on.

private void
loadFile(String sourcePath)

Extracts the source file and calls System.load.

private Throwable

Returns:

null if the file was extracted and loaded.
loadFile
(String sourcePath, String sourceCrc, File extractedFile)

public String
mapLibraryName(String libraryName)

Maps a platform independent library name to a platform dependent name.

pack-priv static String
private InputStream
public static synchronized void
setLoaded(String libraryName)

Sets the library as loaded, for when application code wants to handle libary loading itself.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

architectureback to summary
public static Architecture architecture
bitnessback to summary
public static Architecture.Bitness bitness
is64Bitback to summary
public static boolean is64Bit

Deprecated

Use bitness as SharedLibraryLoader.bitness == Architecture.Bitness._64 instead.

Annotations
@Deprecated
isAndroidback to summary
public static boolean isAndroid

Deprecated

Use os as SharedLibraryLoader.os == Os.Android instead.

Annotations
@Deprecated
isARMback to summary
public static boolean isARM

Deprecated

Use architecture as SharedLibraryLoader.architecture == Architecture.ARM instead.

Annotations
@Deprecated
isIosback to summary
public static boolean isIos

Deprecated

Use os as SharedLibraryLoader.os == Os.IOS instead.

Annotations
@Deprecated
isLinuxback to summary
public static boolean isLinux

Deprecated

Use os as SharedLibraryLoader.os == Os.Linux instead.

Annotations
@Deprecated
isMacback to summary
public static boolean isMac

Deprecated

Use os as SharedLibraryLoader.os == Os.MacOsX instead.

Annotations
@Deprecated
isWindowsback to summary
public static boolean isWindows

Deprecated

Use os as SharedLibraryLoader.os == Os.Windows instead.

Annotations
@Deprecated
loadedLibrariesback to summary
private static final HashSet<String> loadedLibraries
nativesJarback to summary
private String nativesJar
osback to summary
public static Os os
randomback to summary
private static final Random random

Constructor Detail

SharedLibraryLoaderback to summary
public SharedLibraryLoader()
SharedLibraryLoaderback to summary
public SharedLibraryLoader(String nativesJar)

Fetches the natives from the given natives jar file. Used for testing a shared lib on the fly.

Method Detail

canExecuteback to summary
private boolean canExecute(File file)
canWriteback to summary
private boolean canWrite(File file)

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

closeQuietlyback to summary
public static void closeQuietly(Closeable c)
crcback to summary
public String crc(InputStream input)

Returns a CRC of the remaining bytes in the stream.

extractFileback to summary
public File extractFile(String sourcePath, String dirName) throws IOException

Extracts the specified file to the specified directory if it does not already exist or the CRC does not match. If file extraction fails and the file exists at java.library.path, that file is returned.

Parameters
sourcePath:String

The file to extract from the classpath or JAR.

dirName:String

The name of the subdirectory where the file will be extracted. If null, the file's CRC will be used.

Returns:File

The extracted file.

extractFileback to summary
private File extractFile(String sourcePath, String sourceCrc, File extractedFile) throws IOException
extractFileToback to summary
public void extractFileTo(String sourcePath, File dir) throws IOException

Extracts the specified file into the temp directory if it does not already exist or the CRC does not match. If file extraction fails and the file exists at java.library.path, that file is returned.

Parameters
sourcePath:String

The file to extract from the classpath or JAR.

dir:File

The location where the extracted file will be written.

getExtractedFileback to summary
private File getExtractedFile(String dirName, String fileName)

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

Returns:File

null if a writable path could not be found.

isLoadedback to summary
public static synchronized boolean isLoaded(String libraryName)
loadback to summary
public void load(String libraryName)

Loads a shared library for the platform the application is running on.

Parameters
libraryName:String

The platform independent library name. If not contain a prefix (eg lib) or suffix (eg .dll).

loadFileback to summary
private void loadFile(String sourcePath)

Extracts the source file and calls System.load. Attemps to extract and load from multiple locations. Throws runtime exception if all fail.

loadFileback to summary
private Throwable loadFile(String sourcePath, String sourceCrc, File extractedFile)
Returns:Throwable

null if the file was extracted and loaded.

mapLibraryNameback to summary
public String mapLibraryName(String libraryName)

Maps a platform independent library name to a platform dependent name.

randomUUIDback to summary
pack-priv static String randomUUID()
readFileback to summary
private InputStream readFile(String path)
setLoadedback to summary
public static synchronized void setLoaded(String libraryName)

Sets the library as loaded, for when application code wants to handle libary loading itself.