Mike/Lars/Mark (and other Gurus),
Please help!
Can FWRITE instrinsic be invoked as 'FWRITE.invoke()' in java programs.
I need to be able to open, and write to an MPE Message file using Java
program. I realize I could use JNI. But, can I accomplish the task using MPE
Class files only.
If you could provide some sample code, that would be a great help to me.
Thanks.
My test program attached below:
file://: myFileTest.java
import com.hp.mpe.*;
/** Test ability to call file system intrinsics. This program may
* change drastically when File, FileReader, and FileWriter objects
* are created for the MPE Class Library.
*/
public class myFileTest {
// ITEM NUMBER constants
public static final int END_LIST = 0;
public static final int ITEM_FORMALDESIGNATOR = 2;
public static final int ITEM_DOMAIN = 3;
// ITEM VALUE constants
public static final int DOMAIN_OLD = 3;
// CONDITION CODE constants
public static final int CCG = 0;
public static final int CCL = 1;
public static final int CCE = 2;
private static String jar = new String("sysintr.jar");
public void decodeStatus(int status) {
short info = (short)(status >> 16);
short subsys = (short)status;
System.out.println("decodeStatus " + subsys + ", " + info);
printFSErrorMessage(info);
}
public int getFSError(int filenum) {
Intrinsic FCHECK = Intrinsic.loadFromJar(jar, "FCHECK");
FCHECK.setParameter(0, new Integer(filenum));
FCHECK.setParameter(1, new Integer(0));
try {
FCHECK.invoke();
} catch (MPEException me) { me.printStackTrace(); }
return ((Integer)FCHECK.getParameter(1).getParmValue()).intValue();
}
public void printTombstone(int filenum) {
Intrinsic PRINTFILEINFO = Intrinsic.loadFromJar(jar, "PRINTFILEINFO");
PRINTFILEINFO.setParameter(0, new Integer(filenum));
try {
PRINTFILEINFO.invoke();
} catch (Exception e) { e.printStackTrace(); }
}
public void printFSErrorMessage(short fserr) {
Intrinsic FERRMSG = Intrinsic.loadFromJar(jar, "FERRMSG");
FERRMSG.setParameter(0, new Integer((int)fserr));
FERRMSG.setParameter(1, new byte[72]);
FERRMSG.setParameter(2, new Integer(-72));
try {
FERRMSG.invoke();
} catch (MPEException me) { me.printStackTrace(); }
System.out.println(new String((byte[])
FERRMSG.getParameter(1).getParmValue()));
}
public void run() {
boolean eof = false;
Integer ccode = new Integer(0);
Short readCount = new Short((short)0);
int filenum, status;
Intrinsic HPFOPEN = Intrinsic.loadFromJar(jar, "HPFOPEN");
Intrinsic FWRITE = Intrinsic.loadFromJar(jar, "FWRITE");
Intrinsic FCLOSE = Intrinsic.loadFromJar(jar, "FCLOSE");
Intrinsic CCODE = Intrinsic.loadFromJar(jar, "CCODE");
HPFOPEN.setParameter(0, new Integer(0)); /* filenum */
HPFOPEN.setParameter(1, new Integer(0)); /* status */
HPFOPEN.setParameter(2, new Integer(ITEM_DOMAIN));
HPFOPEN.setParameter(3, new Integer(DOMAIN_OLD));
HPFOPEN.setParameter(4, new Integer(ITEM_FORMALDESIGNATOR));
HPFOPEN.setParameter(5, (new
String("/XDLR/PUB/VNM2000D").getBytes()));
HPFOPEN.setParameter(6, new Integer(END_LIST));
try {
HPFOPEN.invoke();
} catch (MPEException me) { me.printStackTrace(); }
System.out.println("File Opened");
filenum =
((Integer)HPFOPEN.getParameter(0).getParmValue()).intValue();
status =
((Integer)HPFOPEN.getParameter(1).getParmValue()).intValue();
if (status != 0) {
decodeStatus(status);
System.exit(-1);
}
System.out.println("HPFOPEN returns file number " + filenum );
String recvalue = new String("This is a myFileTestRecord");
byte[] recbytes = recvalue.getBytes();
FWRITE.setParameter(0, new Short((short)filenum));
FWRITE.setParameter(1, recbytes);
FWRITE.setParameter(2, new Short((short)-106));
// warning: trace causes FWRITEs to happen, which reset ccode!
file://FREAD.setTrace(true);
try {
FWRITE.invoke();
ccode = (Integer) CCODE.invoke();
} catch (Exception e) { e.printStackTrace(); }
if (ccode.intValue() == CCE) {
System.out.println(
new String((byte[])(FWRITE.getParameter(1).getParmValue())));
} else if (ccode.intValue() == CCG) {
eof = true;
System.out.println("<< EOF >>");
} else {
printFSErrorMessage((short)getFSError(filenum));
printTombstone(filenum);
eof = true;
}
FCLOSE.setParameter(0, new Integer(filenum));
FCLOSE.setParameter(1, new Integer(0));
FCLOSE.setParameter(2, new Integer(0));
try {
FCLOSE.invoke();
} catch (MPEException e) { e.printStackTrace(); }
}
public static void main(String[] args) {
myFileTest f = new myFileTest();
f.run();
}
}
rgds,
daniel
|