DirectIPPrintJob.java 1.95 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.fd.stp.internal.print.jobs;

import com.adobe.fd.stp.api.PrinterProtocol;
import com.adobe.fd.stp.internal.exception.STPServiceException;
import com.adobe.fd.stp.internal.logging.STPServiceLogger;
import com.adobe.fd.stp.internal.print.jobs.TCPPrintJob;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class DirectIPPrintJob
extends TCPPrintJob {
    private static STPServiceLogger logger = new STPServiceLogger(DirectIPPrintJob.class);
    private static final int mnDefaultPortNo = 9100;
    private static final String DirectIP = PrinterProtocol.DirectIP.toString();

    public DirectIPPrintJob(String sPrinterUri, String sPrinterName) throws STPServiceException {
        super(sPrinterUri, sPrinterName, 9100);
    }

    @Override
    public void print(InputStream inStream) throws STPServiceException {
        Socket printerSoc = null;
        PrintStream printerStream = null;
        String sPrinterIP = this.getServer();
        try {
            printerSoc = this.connect(DirectIP);
            printerStream = new PrintStream(printerSoc.getOutputStream());
            int bytes = 0;
            byte[] chunk = new byte[8192];
            while ((bytes = inStream.read(chunk)) != -1) {
                printerStream.write(chunk, 0, bytes);
            }
        }
        catch (UnknownHostException e) {
            logger.error("AEM_STP_001_004", new String[]{sPrinterIP + ":" + e.getMessage()});
            throw new STPServiceException("AEM_STP_001_004", new String[]{sPrinterIP}, e);
        }
        catch (Exception e) {
            logger.error("AEM_STP_001_002", new String[]{sPrinterIP + ":" + e.getMessage()});
            throw new STPServiceException("AEM_STP_001_002", new String[]{sPrinterIP}, e);
        }
        finally {
            this.closeAll(printerSoc, null, printerStream);
        }
    }
}