CUPSPrintJob.java
4.72 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
/*
* 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.print.jobs.TCPPrintJob;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class CUPSPrintJob
extends TCPPrintJob {
private static final String CUPS = PrinterProtocol.CUPS.toString();
private static final String sRequestMethod = "POST";
private static final String CONTENT_TYPE = "Content-type";
private static final String APPLICATION_IPP = "application/ipp";
private static final String ATTRIBUTES_CHARSET = "attributes-charset";
private static final String US_ASCII = "us-ascii";
private static final String NATURAL_LANGUAGE = "attributes-natural-language";
private static final String EN_US = "en-us";
private static final String PRINTER_URI = "printer-uri";
public CUPSPrintJob(String sPrintServerUri, String sPrinterName) {
super(sPrintServerUri, sPrinterName);
}
private HttpURLConnection connect() throws STPServiceException {
HttpURLConnection connection = null;
String sCUPSServerName = this.getServer();
try {
URL url = new URL(sCUPSServerName);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "application/ipp");
}
catch (Exception e) {
throw new STPServiceException("AEM_STP_001_004", new String[]{sCUPSServerName}, e);
}
return connection;
}
private void close(URLConnection socket, InputStream in, OutputStream out) {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
catch (Exception var4_4) {
// empty catch block
}
}
@Override
public boolean isAccessible() {
return true;
}
@Override
public void print(InputStream inStream) throws STPServiceException {
block10 : {
HttpURLConnection printer = null;
InputStream oResponseStream = null;
DataOutputStream out = null;
String sPrinter = this.getServer();
if (sPrinter == null) {
throw new STPServiceException("AEM_STP_001_003", new Object[]{"sPrinter is null"});
}
try {
printer = this.connect();
out = new DataOutputStream(printer.getOutputStream());
out.writeShort(257);
out.writeShort(2);
out.writeInt(1);
out.writeByte(1);
out.writeByte(71);
out.writeShort("attributes-charset".length());
out.write("attributes-charset".getBytes());
out.writeShort("us-ascii".length());
out.write("us-ascii".getBytes());
out.writeByte(72);
out.writeShort("attributes-natural-language".length());
out.write("attributes-natural-language".getBytes());
out.writeShort("en-us".length());
out.write("en-us".getBytes());
out.writeByte(69);
out.writeShort("printer-uri".length());
out.write("printer-uri".getBytes());
out.writeShort(sPrinter.length());
out.write(sPrinter.getBytes());
out.writeByte(3);
int len = 0;
byte[] readbuf = new byte[8192];
while ((len = inStream.read(readbuf)) > 0) {
out.write(readbuf, 0, len);
}
out.flush();
oResponseStream = printer.getInputStream();
len = oResponseStream.read(readbuf);
if (len != -1) {
if (readbuf[2] != 0 && readbuf[3] != 0) {
throw new STPServiceException("AEM_STP_001_005", new String[]{CUPS, sPrinter});
}
break block10;
}
throw new STPServiceException("AEM_STP_001_005", new String[]{CUPS, sPrinter});
}
catch (STPServiceException e) {
throw e;
}
catch (Exception e) {
throw new STPServiceException("AEM_STP_001_005", new String[]{CUPS, sPrinter});
}
finally {
this.close(printer, oResponseStream, out);
}
}
}
}