LPDPrintJob.java
5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* 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.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Random;
public class LPDPrintJob
extends TCPPrintJob {
private static STPServiceLogger logger = new STPServiceLogger(LPDPrintJob.class);
private static final int mnDefaultPortNo = 515;
private String msUserName = "dummy";
private final int ASCII_SP = 32;
private final int ASCII_LF = 10;
private static final String LPD = PrinterProtocol.LPD.toString();
public LPDPrintJob(String sPrintServerUri, String sPrinterName) throws STPServiceException {
super(sPrintServerUri, sPrinterName, 515);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public boolean isAccessible() {
boolean bSuccess;
Socket printer = null;
bSuccess = true;
DataInputStream in = null;
DataOutputStream out = null;
String sPrinterName = this.getPrinterName();
try {
printer = this.connect(LPD);
in = new DataInputStream(printer.getInputStream());
out = new DataOutputStream(printer.getOutputStream());
out.write(2);
out.writeBytes(sPrinterName);
out.write(10);
out.flush();
if (in.readByte() != 0) {
bSuccess = false;
}
}
catch (Exception e) {
logger.error("AEM_STP_001_004", new String[]{sPrinterName + ":" + e.getMessage()});
bSuccess = false;
}
finally {
this.closeAll(printer, in, out);
}
return bSuccess;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void print(InputStream inStream) throws STPServiceException {
boolean bSuccess;
String sPrinterName;
Socket printer = null;
bSuccess = true;
DataInputStream in = null;
DataOutputStream out = null;
String document = "dummy doc";
Random jobIdGen = new Random();
String jobid = String.valueOf(jobIdGen.nextInt(999) + 1);
String sLocalHostName = "dummy";
try {
sLocalHostName = InetAddress.getLocalHost().getHostName();
}
catch (Exception var10_10) {
// empty catch block
}
sPrinterName = this.getPrinterName();
if (sPrinterName == null) {
throw new STPServiceException("AEM_STP_001_001", new String[]{"printerName"});
}
try {
printer = this.connect(LPD);
in = new DataInputStream(printer.getInputStream());
out = new DataOutputStream(printer.getOutputStream());
String dname = "dfA" + jobid + sLocalHostName;
String cname = "cfA" + jobid + sLocalHostName;
String controlString = "H" + sLocalHostName + "\n" + "P" + this.msUserName + "\n" + "f" + dname + "\n" + "U" + dname + "\n" + "N" + document + "\n";
out.write(2);
out.writeBytes(sPrinterName);
out.write(10);
out.flush();
if (in.readByte() != 0) {
bSuccess = false;
}
out.write(2);
out.writeBytes(String.valueOf(controlString.length()));
out.write(32);
out.writeBytes(cname);
out.write(10);
out.flush();
byte by = in.readByte();
if (by != 0) {
bSuccess = false;
}
out.writeBytes(controlString);
out.write(0);
out.flush();
by = in.readByte();
if (by != 0) {
bSuccess = false;
}
out.write(3);
out.writeBytes(String.valueOf(inStream.available()));
out.write(32);
out.writeBytes(dname);
out.write(10);
out.flush();
by = in.readByte();
if (by != 0) {
bSuccess = false;
}
int bytes = 0;
byte[] buffer = new byte[8192];
while ((bytes = inStream.read(buffer)) > 0) {
out.write(buffer, 0, bytes);
}
out.write(0);
out.flush();
by = in.readByte();
if (by != 0) {
bSuccess = false;
}
}
catch (Exception e) {
logger.error("AEM_STP_001_005", new String[]{LPD, sPrinterName + ":" + e.getMessage()});
bSuccess = false;
}
finally {
this.closeAll(printer, in, out);
}
if (!bSuccess) {
throw new STPServiceException("AEM_STP_001_005", new String[]{LPD, sPrinterName});
}
}
}