TE.java
4.42 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
package com.cnlive.socket;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.StatusLine;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.io.FileUtils;
import com.cnlive.mz.commons.net.HttpReq;
import com.cnlive.mz.live.common.BaseUtil;
public class TE {
public static void main(String[] args) {
// new
// TE().doGet("http://bc.cnlive.com/live/epg/play/swf?appId=82_irej0pbo53&channelId=7a817495-cc2a-4ab2-85b8-25c7b0a312e3");
//new TE().aa("test1");
File files[] = new File("e:/json").listFiles();
for (int i = 0; i < files.length; i++) {
File f = files[i];
System.out.println(f.getName());
String jsob = "";
try {
jsob = FileUtils.readFileToString(f,"utf-8");
FileUtils.writeStringToFile(f,jsob,"utf-8");
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void res(String streamName) {
try {
String accesskey = BaseUtil.getAccessKey();
accesskey = java.net.URLEncoder.encode(accesskey, "utf-8");
String signature = BaseUtil.signature(streamName);
String del = "del";
String delsignature = BaseUtil.signature(del, streamName);
String expire = BaseUtil.getTimestamp();
String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey + "&expire=" + expire
+ "&app=live&method=del&name=" + streamName;
String jsonArrStr = HttpReq.getRequestWidthResult(url);
System.out.println("..jsonArrStr.." + jsonArrStr);
} catch (Exception e) {
e.printStackTrace();
}
}
public void aa(String streamName) {
try {
String accesskey = BaseUtil.getAccessKey();
accesskey = java.net.URLEncoder.encode(accesskey, "utf-8");
String signature = BaseUtil.signature(streamName);
String add = "add";
String addsignature = BaseUtil.signature(add, streamName);
String expire = BaseUtil.getTimestamp();
System.out.println(expire + "---expire---");
String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey + "&expire=" + expire
+ "&app=live&method=del&name=" + streamName;
System.out.println(url);
String jsonArrStr = HttpReq.getRequestWidthResult(url);
int status = HttpReq.getRequest(url);
System.out.println(status + "......and......" + jsonArrStr);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
private HttpClient getHttpClient() {
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(2200);
client.getHttpConnectionManager().getParams().setSoTimeout(2200);
return client;
}
public void doGet(String url) {
BufferedReader in = null;
HttpClient client = this.getHttpClient();
HttpMethod method = new GetMethod(url);
method.setFollowRedirects(false);
InputStream stream = null;
try {
int exeCode = client.executeMethod(method);
StatusLine status = method.getStatusLine();
int statusCode = status.getStatusCode();
StringBuffer buf = new StringBuffer();
if (statusCode == 301 || statusCode == 302) {
Header[] hs = method.getResponseHeaders("Location");
for (Header h : hs) {
System.out.println(h.getName() + "--" + h.getValue());
String playUrl = h.getValue();
}
Header[] hss = method.getResponseHeaders("message");
for (Header h : hss) {
System.out.println(h.getName() + "--" + h.getValue());
String playUrl = h.getValue();
}
} else {
stream = method.getResponseBodyAsStream();
in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
String line;
while (null != (line = in.readLine())) {
buf.append(line).append("\n");
}
System.out.println(buf.toString());
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (stream != null) {
try {
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
method.releaseConnection();
}
}
}