All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.com.ibm.as400.access.SpooledFileOutputStream Maven / Gradle / Ivy

The newest version!
///////////////////////////////////////////////////////////////////////////////
//                                                                             
// 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:
      * 
      * 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); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy