wsh/vbs supports moniker access to Java class files (either built-in system classes, or custom add-on classes). This method can be used on any win32 platform that has the MS JVM installed (Win95, 98, ME, NT4, Win2000 [and XP if JVM is manually installed]). As an example, the FileOutputStream class, wrapped with a BufferedOutputStream, has been wrapped into a very simple utility class FileOutputUtil.java which when compiled, can be used to easily output any byte data to a binary file from a vbs script. This class simply instantiates an instance of the FileOutputStream class, and exposes the close() and write(byte) methods of that class. (read capability can be easily added). Typical performance is ~ 120 kb/sec file writing for 850 MHz Pentium III. The FileOutputUtil compiled class is very small (681 bytes). It can easily be used with any vbs script by placing the class file into the same directory as the vbs script, or into the directory %windir%\Java\Classes making this utility class available for any vbs scripts. The class does NOT need to be registered as COM to be used as a moniker from script.
The following procedure shows one way to use the FileOutputUtil class:
Sub SaveBinaryJava (FileName, StringBuffer)
dim oJFile, i
set oJFile = GetObject("java:FileOutputUtil")
oJFile.openFile(FileName)
For i=1 to Lenb(StringBuffer)
oJFile.writebyte(Ascb(Midb(StringBuffer,I,1)))
Next
oJFile.closeFile()
End Sub
This example can accept a binary-packed string, and outputs the binary data to a file. If a regular vbs String is passed (UNICODE encoded internally), then the file will contain the *UNICODE* byte representation (2 bytes/character). Note that the oJFile.writebyte(bytevalue) method can be used to write ANY binary byte values. The bytevalue is truncated to an 8 bit value for values larger than 255. The CAPICOM script sample SaveBinCert.vbs demonstrates using this class to save a certificate object (encoded as a binary-packed string) to a binary DER certificate file, and compares the java moniker approach described here with an approach using the CAPICOM 2 function Utilities.BinaryStringToByteArray(binString) with ADODB.Stream.