Reading spooled files and AFP resources

You can use the PrintObjectInputStream class to read the raw contents of a spooled file or Advanced Function Printing™ (AFP™) resource from the server. The class extends the standard JDK java.io.InputStream class so that it can be used anywhere an InputStream is used.

Obtain a PrintObjectInputStream object by calling either the getInputStream() method on an instance of the SpooledFile class or the getInputStream() method on an instance of the AFPResource class. Getting an input stream for a spooled file is supported for Version 3 Release 2 (V3R2), V3R7, and later versions of i5/OS™. Getting input streams for AFP resources is supported for V3R7 and later.

Use one of the read() methods for reading from the input stream. These methods all return the number of bytes actually read, or -1 if no bytes were read and the end of file was reached.

Use the available() method of PrintObjectInputStream to return the total number of bytes in the spooled file or AFP resource. The PrintObjectInputStream class supports marking the input stream, so PrintObjectInputStream always returns true from the markSupported() method. The caller can use the mark() and reset() methods to move the current read position backward in the input stream. Use the skip() method to move the read position forward in the input stream without reading the data.

Example

The following example shows how to use PrintObjectInputStream to read an existing server spooled file

Example: Reading spooled files