Example: Read Spooled File

/////////////////////////////////////////////////////////////////////////
// Example that reads an existing AS/400 spooled file.
//
// For more information about AS/400 Printing, refer to :
// 
/////////////////////////////////////////////////////////////////////////
//
// This source is an example of AS/400 Toolbox for Java "PrintObjectInputStream".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind.  The implied warranties of
// merchantablility and fitness for a particular purpose are
// expressly disclaimed.
//
// AS/400 Toolbox for Java
// (C) Copyright IBM Corp. 1997
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
/////////////////////////////////////////////////////////////////////////
        try{
        byte[] buf = new byte[2048];
        int bytesRead;
        AS400 sys = new AS400();
        SpooledFile splf = new SpooledFile( sys,          // AS400
                                            "MICR",       // splf name
                                            17,           // splf number
                                            "QPRTJOB",    // job name
                                            "QUSER",      // job user
                                            "020791" );   // job number

        // open the spooled file for reading and get the input stream to
        // read from it.
        InputStream in = splf.getInputStream(null);

        do
        {
            // read up to buf.length bytes of raw spool data into
            // our buffer.  The actual bytes read will be returned.
            // The data will be a binary printer data stream that is the
            // contents of the spooled file.
            bytesRead = in.read( buf );
            if( bytesRead != -1 )
            {
                // process the spooled file data.
               System.out.println( "Read " + bytesRead + " bytes" );
            }
        } while( bytesRead != -1 );

        in.close();
    }
    catch( Exception e )
    {
        // exception
    }