TCPPrintJob.java
3.71 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.fd.stp.internal.print.jobs;
import com.adobe.fd.stp.internal.exception.STPServiceException;
import com.adobe.fd.stp.internal.print.jobs.IPrintJob;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
public abstract class TCPPrintJob
implements IPrintJob {
private String msPrinterName = null;
private String msServer = null;
private int mnPortNo = -1;
protected static final int mnSocketTimeOut = 180000;
protected TCPPrintJob(String sPrintServerUri, String sPrinterName) {
this.msPrinterName = sPrinterName;
this.msServer = sPrintServerUri;
}
protected static String[] parseIPAdress(String sUri) {
String[] hostAndPort = new String[2];
int index1 = sUri.lastIndexOf(":");
int index2 = sUri.indexOf("]:");
int index3 = sUri.indexOf(":");
if (index2 != -1) {
hostAndPort[0] = sUri.substring(1, index2);
hostAndPort[1] = sUri.substring(index2 + 2);
} else if (sUri.charAt(0) == '[') {
hostAndPort[0] = sUri.substring(1, sUri.length() - 1);
hostAndPort[1] = "";
} else if (index1 == -1) {
hostAndPort[0] = sUri;
hostAndPort[1] = "";
} else if (index3 == index1) {
hostAndPort[0] = sUri.substring(0, index1);
hostAndPort[1] = sUri.substring(index1 + 1);
} else {
hostAndPort[0] = sUri;
hostAndPort[1] = "";
}
return hostAndPort;
}
protected TCPPrintJob(String sPrintServerUri, String sPrinterName, int nDefaultPortNo) throws STPServiceException {
this.mnPortNo = nDefaultPortNo;
this.msPrinterName = sPrinterName;
if (sPrintServerUri != null) {
String[] hostAndPort = TCPPrintJob.parseIPAdress(sPrintServerUri);
this.msServer = hostAndPort[0];
if (hostAndPort[1].length() > 0) {
try {
this.mnPortNo = Integer.parseInt(hostAndPort[1]);
}
catch (Exception e) {
throw new STPServiceException("AEM_STP_001_007", new Object[]{sPrintServerUri}, e);
}
}
}
}
protected Socket connect(String sAccessMechanism) throws STPServiceException {
Socket socket = null;
if (this.msServer == null) {
throw new STPServiceException("AEM_STP_001_001", new String[]{"printerServer"});
}
try {
socket = new Socket(InetAddress.getByName(this.msServer), this.mnPortNo);
socket.setSoTimeout(180000);
}
catch (Exception e) {
throw new STPServiceException("AEM_STP_001_004", new String[]{this.msServer});
}
return socket;
}
protected void closeAll(Socket socket, InputStream in, OutputStream out) {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
if (socket != null) {
socket.close();
}
}
catch (Exception var4_4) {
// empty catch block
}
}
protected void setServerUri(String sServerUri) {
this.msServer = sServerUri;
}
protected void setPrinterName(String sPrinterName) {
this.msPrinterName = sPrinterName;
}
protected int getServerPort() {
return this.mnPortNo;
}
protected String getPrinterName() {
return this.msPrinterName;
}
protected String getServer() {
return this.msServer;
}
@Override
public boolean isAccessible() {
return true;
}
}