I try to display the content of a SpooledFile with the library jt40. I use this code :
public static void printJogLog(AS400 as400, Job j) {
SpooledFile spooledFile = new SpooledFile(as400, "QPJOBLOG", 1, j.getName(), j.getUser(), j.getNumber());
try {
PrintParameterList printParms = new PrintParameterList();
printParms.setParameter(PrintObject.ATTR_WORKSTATION_CUST_OBJECT, "/QSYS.LIB/QWPDEFAULT.WSCST");
printParms.setParameter(PrintObject.ATTR_MFGTYPE, "*WSCST");
PrintObjectPageInputStream is = spooledFile.getPageInputStream(printParms);
PrintObjectTransformedInputStream in = spooledFile.getTransformedInputStream(printParms);
byte[] buf = new byte[32767];
StringBuffer sbuf = new StringBuffer();
int bytesRead = 0;
do {
bytesRead = in.read(buf);
if (bytesRead != -1) { // process the spooled file data.
sbuf.append(new String(buf, 1, bytesRead, "CP936"));
}
} while (bytesRead != -1);
System.out.println(sbuf.toString());
BufferedReader d = new BufferedReader(new InputStreamReader(is, "UTF8"));
String data = "";
String pageSpool = "";
while ((data = d.readLine()) != null) {
pageSpool += data + "\n";
}
System.out.println(pageSpool);
} catch (Exception e) {
e.printStackTrace();
}
}
It prints the content of the SpooledFile but I have problems with special characters. I obtain things like this :
CPF412C Echappement 40 12/02/15 17:08:33,699347 QTAERR QSYS 00EA QSRVALDV QSYS *STMT Module de destination . . . : QSRVALDV Proc俤ure de destination . : OPENVOLUME Instruction . . . . . . . . : 3716 Message . . . . : Cartouche PPRD05 introuvable Cause . . . . . : La cartouche PPRD05 a 倀� indiqu俥 pour l'unit� de bandoth妐ue TAPVTL01, mais elle n'existe pas dans l'unit� TAPVTL01. Que faire . . . : Effectuez l'une des op俽ations suivantes, puis renouvelez votre demande : -- Sp俢ifiez un identificateur de cartouche correct ou ins俽ez la cartouche dans la biblioth妐ue. La cartouche en a peut-坱re 倀� retir俥. -- Si vous avez indiqu� VOL(*MOUNT), l'identificateur de la cartouche n'a peut-坱re pas 倀� d倀ermin�. Indiquez une cartouche pour le param妕re VOL. -- Si l'incident persiste, mettez l'unit� hors fonction, puis remettez-la en fonction � l'aide de la commande VRYCFG (Changer l'倀at d'une configuration) en indiquant le param妕re RESET(*YES). -- Si la commande ADDTAPCTG (Ajouter une cartouche de bande) a 倀� 俶ise, il se peut que la cartouche ait 倀� retir俥 du guichet en libre-service avant son utilisation.
I think I need to set some parameters for the PrintObjet but I don't know how to choose the good parameters and values.
Can someone explain me how to know which parameter I need ?
I found a solution here : http://fixunix.com/ibm-as400/258696-java-read-french-spool.html
I modify my function like this :
public static void printJobLog2(AS400 as400, Job job) {
SpooledFile spooledFile = new SpooledFile(as400, "QPJOBLOG", 1, job.getName(), job.getUser(), job.getNumber());
PrintParameterList printParms = new PrintParameterList();
printParms.setParameter(PrintObject.ATTR_WORKSTATION_CUST_OBJECT, "/QSYS.LIB/QWPDEFAULT.WSCST");
printParms.setParameter(PrintObject.ATTR_MFGTYPE, "*WSCST");
try {
InputStreamReader in = new
InputStreamReader(spooledFile.getTransformedInputStream(printParms), "cp850");
char[] buf = new char[32767];
StringBuffer sbuf = new StringBuffer();
if (in.ready()) {
int bytesRead = 0;
bytesRead = in.read(buf, 0, buf.length);
while (bytesRead > 0) {
sbuf.append(buf, 0, bytesRead);
bytesRead = in.read(buf, 0, buf.length);
}
}
System.out.println(sbuf.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
Now it works.
CPF412C Echappement 40 16/02/15 08:55:14,184776 QTAERR QSYS 00EA QSRVALDV QSYS *STMT Module de destination . . . : QSRVALDV Procédure de destination . : OPENVOLUME Instruction . . . . . . . . : 3716 Message . . . . : Cartouche SCOH07 introuvable Cause . . . . . : La cartouche SCOH07 a été indiquée pour l'unité de bandothèque TAPVTL01, mais elle n'existe pas dans l'unité TAPVTL01.