Search in sources :

Example 1 with PrintObjectTransformedInputStream

use of com.ibm.as400.access.PrintObjectTransformedInputStream in project IBMiProgTool by vzupka.

the class WrkSplF method convertSpooledFile2.

/**
 * Read and transform spooled file data using automatic conversion;
 *
 * This method is not used because it does not give satisfying results:
 * - Does not render non-ASCII characteres, they are replaced by a substitute character
 * - Headings are sometimes incorrectly formatted (not on the next line)
 *
 * @param splf
 * @return
 */
protected String convertSpooledFile2(SpooledFile splf) {
    try {
        Integer numberParInt = new Integer(numberPar);
        PrintParameterList printParameterList = new PrintParameterList();
        printParameterList.setParameter(SpooledFile.ATTR_SPOOLFILE, namePar);
        printParameterList.setParameter(SpooledFile.ATTR_SPLFNUM, numberParInt);
        printParameterList.setParameter(SpooledFile.ATTR_JOBNAME, jobPar);
        printParameterList.setParameter(SpooledFile.ATTR_JOBUSER, userPar);
        printParameterList.setParameter(SpooledFile.ATTR_JOBNUMBER, jobNumberPar);
        printParameterList.setParameter(SpooledFile.ATTR_DATE, datePar);
        printParameterList.setParameter(SpooledFile.ATTR_TIME, timePar);
        printParameterList.setParameter(PrintObject.ATTR_MFGTYPE, "*WSCST");
        printParameterList.setParameter(PrintObject.ATTR_WORKSTATION_CUST_OBJECT, "/QSYS.LIB/QWPDEFAULT.WSCST");
        // Read the spooled file attributes for determining if it is AFPDS or SCS type spool file
        String stringAttribute = splf.getStringAttribute(PrintObject.ATTR_PRTDEVTYPE);
        if ((stringAttribute != null) && (stringAttribute.equals("*AFPDS"))) {
        // Not applicable
        } else if ((stringAttribute != null) && (stringAttribute.equals("*SCS"))) {
            PrintObjectTransformedInputStream inputStream = splf.getTransformedInputStream(printParameterList);
            System.out.println(splf.getStringAttribute(PrintObject.ATTR_CODEPAGE));
            // Read the input stream buffer and create a string buffer
            byte[] bytes = new byte[32767];
            StringBuilder buffer = new StringBuilder();
            // int bytesRead = 0;
            int bytesRead = inputStream.read(bytes);
            while (bytesRead >= 0) {
                bytesRead = inputStream.read(bytes);
                // System.out.println(bytesRead);
                if (bytesRead > 0) {
                    buffer.append(new String(bytes, 0, bytesRead));
                }
            }
            // System.out.println(buffer);
            spoolTextArea = new JTextArea(buffer.toString());
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        return "ERROR";
    }
    return "";
}
Also used : JTextArea(javax.swing.JTextArea) PrintObjectTransformedInputStream(com.ibm.as400.access.PrintObjectTransformedInputStream) PrintParameterList(com.ibm.as400.access.PrintParameterList) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException)

Aggregations

PrintObjectTransformedInputStream (com.ibm.as400.access.PrintObjectTransformedInputStream)1 PrintParameterList (com.ibm.as400.access.PrintParameterList)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 JTextArea (javax.swing.JTextArea)1