001package edu.wpi.first.wpilibj.hal; 002 003import java.io.File; 004import java.io.InputStream; 005import java.io.OutputStream; 006import java.io.FileOutputStream; 007import java.nio.ByteBuffer; 008 009// 010// base class for all JNI wrappers 011// 012public class JNIWrapper 013{ 014 static boolean libraryLoaded = false; 015 static File jniLibrary = null; 016 static 017 { 018 try 019 { 020 if( !libraryLoaded ) 021 { 022 // create temporary file 023 jniLibrary = File.createTempFile("libwpilibJavaJNI", ".so"); 024 // flag for delete on exit 025 jniLibrary.deleteOnExit(); 026 027 byte [] buffer = new byte[1024]; 028 029 int readBytes; 030 031 InputStream is = JNIWrapper.class.getResourceAsStream("/linux-arm/libwpilibJavaJNI.so"); 032 033 OutputStream os = new FileOutputStream(jniLibrary); 034 035 try 036 { 037 while((readBytes = is.read(buffer)) != -1 ) 038 { 039 os.write(buffer, 0, readBytes); 040 } 041 042 } 043 finally 044 { 045 os.close(); 046 is.close(); 047 } 048 049 050 libraryLoaded = true; 051 } 052 053 System.load(jniLibrary.getAbsolutePath()); 054 } 055 catch( Exception ex ) 056 { 057 ex.printStackTrace(); 058 System.exit(1); 059 } 060 } 061 public static native ByteBuffer getPortWithModule(byte module, byte pin); 062 public static native ByteBuffer getPort(byte pin); 063}