TE.java 4.42 KB
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();
		}
	}

}