~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar-CoreAudio/src/org/herac/tuxguitar/player/impl/midiport/coreaudio/JNILibraryLoader.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.player.impl.midiport.coreaudio;
 
2
 
 
3
import java.io.File;
 
4
 
 
5
public class JNILibraryLoader {
 
6
        
 
7
        private static final String JNI_EXTENSION = ".jnilib";  
 
8
        
 
9
        //private static final String JNI_TMP_PATH = (System.getProperty( "java.io.tmpdir" ) + File.separator);
 
10
        
 
11
        public static void loadLibrary(String libname){
 
12
                System.out.println("trying to load" + libname + " (void loadLibrary)");
 
13
                JNILibraryLoader.loadFromClassPath(libname + JNI_EXTENSION);
 
14
                /*
 
15
                if(!JNILibraryLoader.loadFromClassPath(libname + JNI_EXTENSION)){
 
16
                        //System.loadLibrary(libname);
 
17
                }
 
18
                 */
 
19
        }
 
20
        
 
21
        private static boolean loadFromClassPath(String filename){
 
22
                System.out.println("trying to load" + filename + " (bool loadFromClassPath)");
 
23
                
 
24
                File file = new File(/*JNI_TMP_PATH +*/ filename);
 
25
                /*
 
26
                try{
 
27
                        if(!file.exists()){
 
28
                                OutputStream outputStream = new FileOutputStream(file);
 
29
                                InputStream inputStream = JNILibraryLoader.class.getClassLoader().getResourceAsStream(filename);
 
30
                                if (inputStream != null) {
 
31
                                        int read;
 
32
                                        byte [] buffer = new byte [4096];
 
33
                                        while ((read = inputStream.read (buffer)) != -1) {
 
34
                                                outputStream.write(buffer, 0, read);
 
35
                                        }
 
36
                                        outputStream.close();
 
37
                                        inputStream.close();
 
38
                                }
 
39
                        }
 
40
                        */
 
41
                        if(file.exists()){
 
42
                                System.out.println("calling file.getAbsolutePath() : "+ file.getAbsolutePath());
 
43
                                System.load(file.getAbsolutePath());
 
44
                                //System.load(file.getAbsolutePath());
 
45
                                return true;
 
46
                        }
 
47
                        //else
 
48
                        //{
 
49
                                System.out.println("Can't find file " + file.getAbsolutePath());
 
50
                                return false;
 
51
                        //}
 
52
                        /*
 
53
                }catch(Throwable throwable){
 
54
                        return false;
 
55
                }finally{
 
56
                        if(file.exists()){
 
57
                                file.delete();
 
58
                        }
 
59
                }
 
60
                return false;
 
61
                         */
 
62
        }
 
63
}       
 
64
        
 
65