Creating new spooled files

You can use the SpooledFileOutputStream class to create new server spooled files. The class derives from the standard JDK java.io.OutputStream class; after its construction, it can be used anywhere an OutputStream is used.

When creating a new SpooledFileOutputStream, the caller may specify the following:

These parameters are all optional (the caller may pass null of any or all of them). If a printer file is not specified, the network print server uses the default network print printer file, QPNPSPRTF. The output queue parameter is there as a convenience; it also can be specified in the PrintParameterList. If the output queue parameter is specified in both places, the PrintParameterList field overrides the output queue parameter. See the documentation of the SpooledFileOutputStream constructor for a complete list of which attributes may be set in the PrintParameterList for creating new spooled files.

Use one of the write() methods to write data into the spooled file. The SpooledFileOutputStream object buffers the data and sends it when either the output stream is closed or the buffer is full. Buffering is done for two reasons:

Use the flush() method to force the data to be written to the server.

When the caller is finished writing data to the new spooled file, the close() method is called to close the spooled file. Once the spooled file has been closed, no more data can be written to it. By calling the getSpooledFile() method once the spooled file has been closed, the caller can get a reference to a SpooledFile object that represents the spooled file.

Data stream types in spooled files

Use the Printer Data Type attribute of the spooled file to set the type of data to be put into the spooled file. If the caller does not specify a printer data type, the default is to use automatic data typing. This method looks at the first few thousand bytes of the spooled file data, determines if it fits either SNA Character Stream (SCS) or Advanced Function Printing™ data stream (AFPDS) data stream architectures, and then sets the attribute appropriately. If the bytes of spooled file data do not match either of these architectures, the data is tagged as *USERASCII. Automatic data typing works most of the time. The caller generally uses it unless the caller has a specific case in which automatic data typing does not work. In those cases, the caller can set the Printer Data Type attribute to a specific value (for example, *SCS). If the caller wants to use the printer data that is in the printer file, the caller must use the special value *PRTF. If the caller overrides the default data type when creating a spooled file, caution must be used to ensure that the data put into the spooled file matches the data type attribute. Putting non-SCS data into a spooled file that is marked to receive SCS data triggers an error message from the host and the loss of the spooled file.

Generally, this attribute can have three values:

Examples

The following examples show ways you can work with spooled files. The first example shows how to create a spooled file on a server from an input stream. The second example shows how to generate an SCS data stream using the SCS3812Writer class, and how to write the stream to a spooled file on the server.

Example: Creating spooled files

Example: Creating SCS spooled files