1 /* 2 * --------- 3 * |.##> <##.| Open Smart Card Development Platform (www.openscdp.org) 4 * |# #| 5 * |# #| Copyright (c) 1999-2006 CardContact Software & System Consulting 6 * |'##> <##'| Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de) 7 * --------- 8 * 9 * This file is part of OpenSCDP. 10 * 11 * OpenSCDP is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License version 2 as 13 * published by the Free Software Foundation. 14 * 15 * OpenSCDP is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with OpenSCDP; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 // 26 // Function to load a binary file using Java native classes 27 // 28 29 function loadBinaryFile(filename) { 30 31 // Open stream 32 var f = new java.io.FileInputStream(filename); 33 34 // Determine file size 35 var flen = f.available(); 36 37 // Allocate native byte array 38 var bs = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, flen); 39 40 // Read into byte array 41 var len = f.read(bs); 42 43 // Allocate JavaScript ByteBuffer from native/wrapped byte array 44 var bb = new ByteBuffer(bs); 45 46 // Convert to JavaScript ByteString 47 var data = bb.toByteString(); 48 49 return data; 50 } 51