Sha256: f7b23ee33994c8dff3420fb7f494e9d53f8a255b3a3c4c2d4efce1c1c2d6e450
Contents?: true
Size: 1.03 KB
Versions: 5
Compression:
Stored size: 1.03 KB
Contents
function load(/*String*/fileName){ //summary: opens the file at fileName and evals the contents as JavaScript. //Read the file var fileContents = readFile(fileName); //Eval the contents. var Context = Packages.org.mozilla.javascript.Context; var context = Context.enter(); try{ return context.evaluateString(global, fileContents, fileName, 1, null); }finally{ Context.exit(); } } function readFile(/*String*/path, /*String?*/encoding){ //summary: reads a file and returns a string encoding = encoding || "utf-8"; var file = new File(path); var lineSeparator = "\n"; var input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)); try { var stringBuffer = new java.lang.StringBuffer(); var line = ""; while((line = input.readLine()) !== null){ stringBuffer.append(line); stringBuffer.append(lineSeparator); } //Make sure we return a JavaScript string and not a Java string. return new String(stringBuffer.toString()); //String } finally { input.close(); } }
Version data entries
5 entries across 5 versions & 1 rubygems