AbstractUrlConnection.java
2.76 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.aemds.datamanager.impl;
import com.adobe.aemds.datamanager.impl.UrlUtil;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
abstract class AbstractUrlConnection
extends URLConnection {
protected String contentType;
protected String contentLengthStr;
AbstractUrlConnection(URL url) {
super(url);
}
protected String getResourcePath(String protocol) throws Exception {
String pre = protocol + ":";
String urlStr = this.url.toExternalForm();
if (!urlStr.startsWith(pre)) {
throw new MalformedURLException("URL " + urlStr + " is not of the form '" + pre + "*'");
}
int endIdx = (urlStr = urlStr.substring(pre.length())).indexOf(63);
return endIdx == -1 ? urlStr : urlStr.substring(0, endIdx);
}
protected abstract void doConnect() throws Exception;
protected abstract String doGetContentType() throws Exception;
protected abstract long doGetContentLength() throws Exception;
public void connect() throws IOException {
if (!this.connected) {
try {
this.doConnect();
this.contentType = this.doGetContentType();
this.contentLengthStr = String.valueOf(this.doGetContentLength());
}
catch (IOException e) {
throw e;
}
catch (Exception e) {
throw new IOException(UrlUtil.getMessage(e, this.url.toExternalForm(), "CONNECT"), e);
}
this.connected = true;
}
}
public String getContentType() {
try {
this.connect();
}
catch (IOException e) {
throw new RuntimeException(UrlUtil.getMessage(e, this.url.toExternalForm(), "CONNECT"), e);
}
return this.contentType;
}
protected abstract InputStream doGetInputStream() throws Exception;
public InputStream getInputStream() throws IOException {
this.connect();
try {
return this.doGetInputStream();
}
catch (IOException e) {
throw e;
}
catch (Exception e) {
throw new IOException(UrlUtil.getMessage(e, this.url.toExternalForm(), "OPEN_STREAM"), e);
}
}
public String getHeaderField(String name) {
if ("content-length".equals(name)) {
try {
this.connect();
}
catch (IOException e) {
throw new RuntimeException(UrlUtil.getMessage(e, this.url.toExternalForm(), "CONNECT"), e);
}
return this.contentLengthStr;
}
return super.getHeaderField(name);
}
}