package org.ethereum.util;

import java.math.BigInteger;
import java.net.URL;
import java.security.SecureRandom;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;

import javax.swing.ImageIcon;

import org.spongycastle.util.encoders.Hex;

public class Utils {

    private static SecureRandom random = new SecureRandom();

    /**
     * @param hexNum should be in form '0x34fabd34....'
     * @return
     */
    public static String hexStringToDecimalString(String hexNum) {

        boolean match = Pattern.matches("0[xX][0-9a-fA-F]+", hexNum);
        if (!match) throw new Error("The string doesn't conains hex num in form 0x.. : [" + hexNum + "]");

        byte[] numberBytes = Hex.decode(hexNum.substring(2));
        return (new BigInteger(1, numberBytes)).toString();
    }
    
    /** 
     * Return formatted Date String: yyyy.MM.dd HH:mm:ss
     * Based on Unix's time() input in seconds
     * 
     * @param timestamp seconds since start of Unix-time
     * @return String formatted as - yyyy.MM.dd HH:mm:ss
     */
    public static String longToDateTime(long timestamp) {
    	Date date = new Date(timestamp * 1000);
    	DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
    	return formatter.format(date);
    }
    
    public static ImageIcon getImageIcon(String resource) {
        URL imageURL = ClassLoader.getSystemResource(resource);
        ImageIcon image = new ImageIcon(imageURL);
        return image;
    }

    static BigInteger _1000_ = new BigInteger("1000");
    public static String getValueShortString(BigInteger number) {
        BigInteger result = number;
        int pow = 0;
        while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) {
            result = result.divide(_1000_);
            pow += 3;
        }
        return result.toString() + "·(" + "10^" + pow + ")";
    }

    /**
     * @param addr length should be 20
     * @return short string represent 1f21c...
     */
    public static String getAddressShortString(byte[] addr) {

        if (addr == null || addr.length != 20) throw new Error("not an address");

        String addrShort = Hex.toHexString(addr, 0, 3);

        StringBuffer sb = new StringBuffer();
        sb.append(addrShort);
        sb.append("...");

        return sb.toString();
    }

    public static SecureRandom getRandom() {
        return random;
    }

    public static double JAVA_VERSION = getJavaVersion();
    static double getJavaVersion() {
        String version = System.getProperty("java.version");
        int pos = 0, count = 0;
        for ( ; pos<version.length() && count < 2; pos ++) {
            if (version.charAt(pos) == '.') count ++;
        }
        return Double.parseDouble (version.substring (0, pos - 1));
    }

    public static String oneByteToHexString(byte value) {
        String retVal = Integer.toString(value & 0xFF, 16);
        if (retVal.length() == 1) retVal = "0" + retVal;
        return retVal;
    }
}

@@ -37,23 +37,151 @@
 ava.
-math.BigInteger
+io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.math.BigInteger;%0Aimport java.net.HttpURLConnection
 ;%0Aim
@@ -3164,10 +3164,723 @@
 ;%0A    %7D%0A
+%0A%0A    public static String getHTML(String urlToRead) %7B%0A        URL url;%0A        HttpURLConnection conn;%0A        BufferedReader rd;%0A        String line;%0A        String result = %22%22;%0A        try %7B%0A            url = new URL(urlToRead);%0A            conn = (HttpURLConnection) url.openConnection();%0A            conn.setRequestMethod(%22GET%22);%0A            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));%0A            while ((line = rd.readLine()) != null) %7B%0A                result += line;%0A            %7D%0A            rd.close();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return result;%0A    %7D%0A%0A
 %7D%0A

Fix latest build break