src.com.ibm.as400.access.SpooledFileOutputStream Maven / Gradle / Ivy
Show all versions of jt400-jdk8 Show documentation
///////////////////////////////////////////////////////////////////////////////
//
// JTOpen (IBM Toolbox for Java - OSS version)
//
// Filename: SpooledFileOutputStream.java
//
// The source code contained herein is licensed under the IBM Public License
// Version 1.0, which has been approved by the Open Source Initiative.
// Copyright (C) 1997-2000 International Business Machines Corporation and
// others. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////
package com.ibm.as400.access;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
/**
* The SpooledFileOutputStream class is used to write data into a spooled file.
**/
public class SpooledFileOutputStream extends OutputStream
{
//Private Data
private transient AS400 system_;
private transient SpooledFileOutputStreamImpl impl_;
/**
* Constructs a SpooledFileOutputStream object.
* Use this object to create a new spooled file on the given system
* with the specified parameters.
* @param system The system on which to create the spooled file.
* @param options Optional. A print parameter list that contains
* a list of attributes with which to create the spooled file.
* The attributes set in options will
* override those attributes in the printer file that is used.
* The printer file used will be the one specified with the
* printerFile parameter, or if that parameter is null,
* it will be the default network print server printer file (QPNPSPRTF).
* If the output queue is specified in options, it
* will override any output queue passed in the outputQueue
* parameter.
* The following parameters may be set:
*
* -
* ATTR_ALIGN - Align page
*
*
-
* ATTR_BACK_OVERLAY - Back overlay integrated file system Name
*
*
-
* ATTR_BKOVL_DWN - Back overlay offset down
*
*
-
* ATTR_BKOVL_ACR - Back overlay offset across
*
*
-
* ATTR_CPI - Characters per inch
*
*
- (1)
* ATTR_CODEPAGE - Code page
*
*
-
* ATTR_CONTROLCHAR - Control character
*
*
-
* ATTR_CONVERT_LINEDATA - Convert line data
*
*
-
* ATTR_CORNER_STAPLE - Corner staple
*
*
-
* ATTR_COPIES - Copies
*
*
-
* ATTR_DAYS_UNTIL_EXPIRE - Days Until File Expires
*
*
-
* ATTR_DBCSDATA - User-specified DBCS data
*
*
-
* ATTR_DBCSEXTENSN - DBCS extension characters
*
*
-
* ATTR_DBCSROTATE - DBCS character rotation
*
*
-
* ATTR_DBCSCPI - DBCS characters per inch
*
*
-
* ATTR_DBCSSISO - DBCS SO/SI spacing
*
*
-
* ATTR_DFR_WRITE - Defer write
*
*
-
* ATTR_PAGRTT - Degree of page rotation
*
*
-
* ATTR_EDGESTITCH_NUMSTAPLES - Edge Stitch Number of Staples
*
*
-
* ATTR_EDGESTITCH_REF - Edge Stitch Reference
*
*
-
* ATTR_EDGESTITCH_REFOFF - Edge Stitch Reference Offset
*
*
-
* ATTR_ENDPAGE - Ending page
*
*
-
* ATTR_EXPIRATION_DATE - Expiration Date
*
*
- (2)
* ATTR_FILESEP - File separators
*
*
-
* ATTR_FOLDREC - Fold records
*
*
-
* ATTR_FONTID - Font identifier
*
*
-
* ATTR_FORM_DEFINITION - Form definition integrated file system name
*
*
-
* ATTR_FORMFEED - Form feed
*
*
-
* ATTR_FORMTYPE - Form type
*
*
-
* ATTR_FRONT_OVERLAY - Front overlay integrated file system same
*
*
-
* ATTR_FTOVL_ACR - Front overlay offset across
*
*
-
* ATTR_FTOVL_DWN - Front overlay offset down
*
*
- (1)
* ATTR_CHAR_ID - Graphic character set
*
*
-
* ATTR_JUSTIFY - Hardware justification
*
*
-
* ATTR_HOLD - Hold spool file
*
*
-
* ATTR_HOLDPNDSTS - Hold Pending Status
*
*
-
* ATTR_IPP_ATTR_CCSID - IPP Attributes-ccsid
*
*
-
* ATTR_IPP_JOB_ID - IPP Job ID
*
*
-
* ATTR_IPP_JOB_NAME - IPP Job Name
*
*
-
* ATTR_IPP_JOB_NAME_NL - IPP Job Name NL
*
*
-
* ATTR_IPP_JOB_ORIGUSER - IPP Job Originating User Name
*
*
-
* ATTR_IPP_JOB_ORIGUSER_NL - IPP Job Originating User Name NL
*
*
-
* ATTR_IPP_PRINTER_NAME - IPP Printer Name
*
*
-
* ATTR_IPP_ATTR_NL - IPP Natural Language
*
*
-
* ATTR_LPI - Lines per inch
*
*
-
* ATTR_MAXRCDS - Maximum spooled output records
*
*
-
* ATTR_OUTPTY - Output priority
*
*
-
* ATTR_OUTPUT_QUEUE - Output queue integrated file system name
*
*
-
* ATTR_OVERFLOW - Overflow line number
*
*
-
* ATTR_PAGE_DEFINITION - Page definition integrated file system name
*
*
-
* ATTR_PAGELEN - Length of page
*
*
-
* ATTR_MEASMETHOD - Measurement method
*
*
-
* ATTR_PAGEWIDTH - Width of page
*
*
-
* ATTR_MULTIUP - Pages per side
*
*
-
* ATTR_POINTSIZE - Point size
*
*
-
* ATTR_FIDELITY - Print fidelity
*
*
-
* ATTR_DUPLEX - Print on both sides
*
*
-
* ATTR_PRTQUALITY - Print quality
*
*
-
* ATTR_PRTTEXT - Print text
*
*
-
* ATTR_PRINTER - Printer
*
*
-
* ATTR_PRTDEVTYPE - Printer device type
*
*
-
* ATTR_RPLUNPRT - Replace unprintable characters
*
*
-
* ATTR_RPLCHAR - Replacement character
*
*
-
* ATTR_SADDLESTITCH_NUMSTAPLES - Saddle Stitch Number of Staples
*
*
-
* ATTR_SADDLESTITCH_REF - Saddle Stitch Reference
*
*
-
* ATTR_SAVE - Save spooled file
*
*
-
* ATTR_SRCDRWR - Source drawer
*
*
-
* ATTR_SPOOL - Spool the data
*
*
-
* ATTR_SPOOLFILE - Spooled file name
*
*
-
* ATTR_SCHEDULE - Spooled output schedule
*
*
-
* ATTR_STARTPAGE - Starting page
*
*
-
* ATTR_UNITOFMEAS - Unit of measure
*
*
-
* ATTR_USERCMT - User comment
*
*
-
* ATTR_USERDATA - User data
*
*
-
* ATTR_SPLSCS - Spool SCS
*
*
-
* ATTR_USRDEFDATA - User defined data
*
*
- (3)
* ATTR_USRDEFOPT - User defined options
*
*
-
* ATTR_USER_DEFINED_OBJECT - User defined object integrated file system name
*
*
*
* Note 1: Code page and graphical character set are dependent upon each
* other. If you set one you must set the other.
*
* Note 2: The special value of *FILE is not allowed when creating a new
* spooled file.
*
* Note 3: Up to 4 user-defined options may be specified.
*
* Note 4: A page definition can be specified with *LINE data.
*
* @param printerFile Optional. The printer file that should be used
* to create the spooled file. This printer file
* must reside on the same system that the
* spooled file is being created on.
* @param outputQueue Optional. The output queue on which to create the
* spooled file. The output queue must reside on
* the same system that the spooled file
* is being created on.
* @exception AS400Exception If the system returns an error message.
* @exception AS400SecurityException If a security or authority error occurs.
* @exception ErrorCompletingRequestException If an error occurs before the request is completed.
* @exception IOException If an error occurs while communicating with the system.
* @exception InterruptedException If this thread is interrupted.
**/
public SpooledFileOutputStream(AS400 system,
PrintParameterList options,
PrinterFile printerFile,
OutputQueue outputQueue)
throws AS400Exception,
AS400SecurityException,
ErrorCompletingRequestException,
InterruptedException,
IOException
{
if (system == null)
{
Trace.log(Trace.ERROR, "Parameter 'system' is null.");
throw new NullPointerException("system");
}
system_ = system;
chooseImpl();
// Do connect here because it may throw Exceptions.
system_.connectService(AS400.PRINT);
PrinterFileImpl pfi = null;
if (printerFile != null) {
if (printerFile.getImpl() == null) {
printerFile.chooseImpl();
}
pfi = (PrinterFileImpl) printerFile.getImpl();
}
OutputQueueImpl oqi = null;
if (outputQueue != null) {
if (outputQueue.getImpl() == null) {
outputQueue.chooseImpl();
}
oqi = (OutputQueueImpl) outputQueue.getImpl();
}
impl_.createSpooledFileOutputStream(system_.getImpl(),
options,
pfi,
oqi);
}
// A1A - Added method
private void chooseImpl()
{
if (system_ == null) {
Trace.log( Trace.ERROR, "Attempt to use SpooledFileOutputStream before setting system.");
throw new ExtendedIllegalStateException("system",
ExtendedIllegalStateException.PROPERTY_NOT_SET);
}
impl_ = (SpooledFileOutputStreamImpl) system_.loadImpl2("com.ibm.as400.access.SpooledFileOutputStreamImplRemote",
"com.ibm.as400.access.SpooledFileOutputStreamImplProxy");
}
/**
* Closes the stream.
* It must be called to release any resources associated with the stream.
* @exception IOException If an error occurs while communicating with the system.
**/
public void close()
throws IOException
{
impl_.close();
}
/** Flushes the stream. This will write any buffered output bytes.
* @exception IOException If an error occurs while communicating with the system.
**/
public void flush()
throws IOException
{
impl_.flush();
}
/** Returns the spooled file that was created (or is being created) with
* this output stream.
* @return A reference to the spooled file object.
* @throws IOException If an error occurs while communicating with the system.
**/
public SpooledFile getSpooledFile()
throws IOException
{
SpooledFile sf = null;
NPCPIDSplF spID = impl_.getSpooledFile();
try {
spID.setConverter((new Converter(system_.getCcsid(), system_)).impl);
}
catch(UnsupportedEncodingException e) {
if (Trace.isTraceErrorOn())
Trace.log(Trace.ERROR, "Error initializing converter for print object", e);
}
sf = new SpooledFile(system_, spID, null);
return sf;
}
/** Writes a byte of data.
* @param b The byte to be written.
* @exception IOException If an error occurs while communicating with the system.
**/
public void write(int b)
throws IOException
{
byte[] buffer1Byte_ = new byte[1];
buffer1Byte_[0] = (byte)b;
write(buffer1Byte_, 0, 1);
}
/** Writes data.length bytes of data from the byte array
* data to the spooled file.
*
* @param data The data to be written.
* @exception IOException If an error occurs while communicating with the system.
**/
public void write(byte[] data)
throws IOException
{
write(data, 0, data.length);
}
/**
* Writes up to length bytes of data from the byte array data,
* starting at offset, to this spooled file.
*
* @param data The data to be written.
* @param offset The start offset in the data.
* @param length The number of bytes that are written.
*
* @exception IOException If an error occurs while communicating with the system.
**/
public void write(byte data[], int offset, int length)
throws IOException
{
impl_.write(data, offset, length);
}
}