import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String a = System.getProperty("os.arch");
		//String a = test.generateTinyURL("http://kkflashtool.de");
		System.out.println(a);
	}

	
	public static String generateTinyURL(String url2enc) {
		String body;
		try {
			body = "url=" + URLEncoder.encode(url2enc, "UTF-8");
			Pattern pattern = Pattern.compile("\"http(.*)\"");

			URL url = new URL("http://tinyurl.com/create.php");
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setRequestMethod("POST");
			connection.setDoInput(true);
			connection.setDoOutput(true);
			connection.setUseCaches(false);
			connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			connection.setRequestProperty("Content-Length",	String.valueOf(body.length()));

			OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
			writer.write(body);
			writer.flush();

			BufferedReader reader = new BufferedReader(new InputStreamReader(
					connection.getInputStream()));

			for (String line; (line = reader.readLine()) != null;) {
				if (line.contains("data-clipboard-text")) {
					Matcher m = pattern.matcher(line.trim());
					if (m.find()) return(m.group().replace('"', ' ').trim());
				}
			}

			writer.close();
			reader.close();

		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
