public class Loader extends Object
Inspired by the techniques used by usb4java, and the loader written by Klaus Raimer, k@ailis.de . See http://usb4java.org for the web site for the project and https://github.com/usb4java/usb4java for the GitHub repository.
| Modifier and Type | Field and Description |
|---|---|
private static boolean |
available
Indicates whether the library was successfully loaded, which implies we are on a Mac and ready to operate.
|
private static int |
BUFFER_SIZE
How large a buffer should be used for copying the dynamic library out of the jar.
|
private static boolean |
loaded
Indicates whether we have tried to load the library.
|
static String |
NATIVE_LIBRARY_NAME
The file name of our native library.
|
private static File |
tempDir
The temporary directory we will use to extract the native library.
|
| Modifier | Constructor and Description |
|---|---|
private |
Loader()
Prevent instantiation.
|
| Modifier and Type | Method and Description |
|---|---|
private static void |
copy(InputStream input,
File output)
Copies the specified input stream to the specified output file.
|
private static File |
createTempDirectory()
Creates the temporary directory used for unpacking the native library.
|
static boolean |
isAvailable()
Checks whether CoreMidi4J is available on the current system, in other words whether it is a Mac OS X system
and the native library was loaded successfully.
|
private static boolean |
isMacOSX()
Check that we are running on Mac OS X.
|
static void |
load()
Tries to load our native library.
|
private static String |
locateLibrary()
Locates the native library, extracting a temporary copy from our jar it does not already exist in the file system.
|
private static final int BUFFER_SIZE
public static final String NATIVE_LIBRARY_NAME
private static File tempDir
private static boolean loaded
private static boolean available
private Loader()
private static boolean isMacOSX()
private static File createTempDirectory() throws CoreMidiException
This requires review. There is a method java.nio.file.Files.createTempDirectory that creates a temporary directory. However, java.io.File.createTempFile(String,String) creates a file in the default temp directory.
This method creates a temporary directory named coreMidi4J in the default
temp directory. Other code then places the dynamically linked library in
the coreMidi4J directory. Both the dynamically linked library file and the
directory use File.deleteOnExit(). This should work since they will be
deleted in reverse order. However, unexpected crashes could leave the system
in a bad state where some files are not deleted.
CoreMidiException - if there is a problem communicating with CoreMIDIFile.delete(),
File.deleteOnExit()private static void copy(InputStream input, File output) throws IOException
input - The input stream to be copied.output - The output file to which the stream should be copied.IOException - If the copy failed.private static String locateLibrary() throws CoreMidiException
CoreMidiException - if there is a problem finding the librarypublic static void load() throws CoreMidiException
CoreMidiException - if something unexpected happens trying to load the native library on a Mac OS X system.public static boolean isAvailable() throws CoreMidiException
CoreMidiException - if something unexpected happens trying to load the native library on a Mac OS X system.Copyright © 2017. All rights reserved.