/pluggablejs/branches/1.1.0build33/samples/langext.js |
---|
0,0 → 1,31 |
println("Language extensions samples"); |
println("|> Inclusion of langext-included.js, composition of "); |
println("|> an object from different files"); |
function method1_implementation() { |
println("This method is defined in langext.js"); |
} |
var method2_implementation = null; |
// If method2 was defined this way it will fail, it needs to be |
// defined as with method3 |
var obj = { |
method1: method1_implementation, |
method2: method2_implementation, |
method3: function() { |
method3_implementation(); |
} |
}; |
lang.include("langext-included.js"); |
// ... instead, it can be defined now though |
obj.method2 = method2_implementation; |
println("|> calling of methods defined elsewhere:"); |
obj.method1(); |
obj.method2(); |
obj.method3(); |
/pluggablejs/branches/1.1.0build33/samples/interactive-call.js |
---|
0,0 → 1,2 |
net.outlyer.plugins.Shell.interactive($net.outlyer.runtime.pluginEnvironment); |
/pluggablejs/branches/1.1.0build33/samples/langext-included.js |
---|
0,0 → 1,9 |
println("|< langext-included.js loaded"); |
method2_implementation = function() { |
println("This method is defined in langext-included.js"); |
} |
method3_implementation = method2_implementation; |
/pluggablejs/branches/1.1.0build33/samples/zeroer.js |
---|
0,0 → 1,63 |
// This file is put in the public domain |
// |
// $Id$ |
var FILE_SIZE_LIMIT = -1; |
var BUFFER_SIZE = 1024 * 1024; |
var DEFAULT_FILE_NAME = "zeroes"; |
java.lang.System.err.println("Disk Zero Filler v0.2"); |
var DiskZeroFiller = { |
zero: null, |
wipe: null, |
commonFill: null |
}; |
DiskZeroFiller.commonFill = function(filename, buffer) { |
// try |
var fos = new java.io.FileOutputStream(filename, false); |
java.lang.System.err.println(); |
var written = 0; |
var ignore = BUFFER_SIZE * 3; |
var reference = new java.io.File("."); |
var free; |
while (ignore < (free = reference.getUsableSpace())) { |
// Must use this form to not be ambiguous |
fos.write(buffer.array(), 0, buffer.array().length); |
written += buffer.array().length; |
java.lang.System.err.printf("\r%d w %d f // %.2fMiB w %.2fMiB", |
new Array( |
new java.lang.Long(written), new java.lang.Long(free), |
written / 1024.0 / 1024.0, |
free / 1024.0 / 1024.0 |
) |
); |
} |
java.lang.System.err.println(); |
fos.close(); |
}; |
DiskZeroFiller.zero = function(filename) { |
var buffer = java.nio.ByteBuffer.allocate(BUFFER_SIZE); |
java.util.Arrays.fill(buffer.array(), new java.lang.Byte(0)); |
this.commonFill(filename, buffer); |
}; |
DiskZeroFiller.wipe = function(filename) { |
var buffer = java.nio.ByteBuffer.allocate(BUFFER_SIZE); |
java.util.Arrays.fill(buffer.array(), new java.lang.Byte(0)); |
for (var i=0; i<BUFFER_SIZE; i+=2) { |
buffer.array()[i] = new java.lang.Byte(127); |
} |
this.commonFill(filename, buffer); |
}; |
DiskZeroFiller.zero("zeroes"); |
//DiskZeroFiller.wipe("wipe"); |
// vim:set ts=4 et ai: // |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
Added: svn:keywords |
+Rev Id Date |
\ No newline at end of property |
/pluggablejs/branches/1.1.0build33/samples/RhinoRun.java |
---|
0,0 → 1,54 |
// This file is put in the Public Domain, originally published |
// at <http://p.outlyer.net./javacode/> |
// $Id$ |
import java.io.BufferedReader; |
import java.io.File; |
import java.io.FileNotFoundException; |
import java.io.FileReader; |
import javax.script.ScriptEngine; |
import javax.script.ScriptEngineManager; |
import javax.script.ScriptException; |
/** |
* This is a wrapper around the rhino script engine, it will load a file |
* and try to eval() its contents. |
* |
* Usage: RhinoRun [inputfile.js] [inputfile2.js] |
*/ |
public class RhinoRun { |
public static void main(String...args) { |
if (args.length == 0) { |
System.err.printf("Usage: java [...] %s [file1.js [file2.js [...]]]\n", |
RhinoRun.class.getName()); |
System.exit(1); |
} |
final ScriptEngine rhino = new ScriptEngineManager().getEngineByName("rhino"); |
for (final String path : args) { |
try { |
final File file = new File(path); |
if (!file.isFile() || !file.canRead()) { |
throw new FileNotFoundException("Failed to access " + path); |
} |
rhino.eval(new BufferedReader(new FileReader(file))); |
} |
catch (final FileNotFoundException e) { |
System.err.println("Error: " + e.getMessage()); |
if (System.getProperty("debug", "0").equals("1")) { |
e.printStackTrace(System.err); |
} |
} |
catch (final ScriptException e) { |
System.err.println("Error: " + e.getMessage()); |
if (System.getProperty("debug", "0").equals("1")) { |
e.printStackTrace(System.err); |
} |
} |
} |
} |
} |
// vim:set ts=4 et ai: // |
Property changes: |
Added: svn:keywords |
+Rev Id Date |
\ No newline at end of property |
/pluggablejs/branches/1.1.0build33/samples/ui.js |
---|
0,0 → 1,8 |
var file = ui.promptForFile("Choose an appropriate executable"); |
err.println("Chosen file: "+file); |
if (!file.canExecute()) { |
err.println("Not a valid executable"); |
} |
/pluggablejs/branches/1.1.0build33/samples/sandbox.js |
---|
0,0 → 1,30 |
var api = { |
createPE: function() { |
var pe = net.outlyer.plugins.PluginEnvironment.create(); |
pe.exportGlobalObject("input", input); |
pe.exportGlobalObject("out", out); |
pe.exportGlobalObject("err", err); |
return pe; |
}, |
createSandbox: function(uri) { |
return api.createPE().createSandbox(uri); |
}, |
}; |
var sb = api.createSandbox(new java.io.File("sandboxed-sandbox.js").toURI()); |
sb.execute(); |
/* |
do { |
var line = ui.prompt("%> "); |
if (null == line || line.isEmpty()) { |
break; |
} |
} |
while (true); |
*/ |
// vim:set ts=4 et ai: // |
/pluggablejs/branches/1.1.0build33/samples/prefs.js |
---|
0,0 → 1,17 |
var prefs = java.utils.prefs; |
var p = java.util.prefs.Preferences.userRoot(); |
var shell = new net.outlyer.plugins.Shell(); |
var k = java.util.prefs.Preferences.userNodeForPackage(shell.getClass()); |
err.println("user root: " + p); |
err.println("pkg root: " + k); |
k.put("SampleKey", "sampleValue"); |
k.sync(); |
err.println("Read: " + k.get("SampleKey", "none set")); |
k.remove("SampleKey"); |
k.sync(); |
/pluggablejs/branches/1.1.0build33/samples/sandboxed-sandbox.js |
---|
0,0 → 1,3 |
err.println("I'm a sandbox inside a sandbox"); |