⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.java

📁 类似QQ的功能
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
					continue;			}			for (int j = 0; j < seqLen; j++)			{				if (len == 0)					return false;				bt = array[i++];				if ((bt & 0xC0) != 0x80)					return false;				len--;			}			if (len == 0)				break;		}		return true;	}	//#sijapp cond.if modules_TRAFFIC is "true" #	// Returns String value of cost value	public static String intToDecimal(int value)	{		String costString = "";		String afterDot = "";		try		{			if (value != 0)			{				costString = Integer.toString(value / 10000) + ".";				afterDot = Integer.toString(value % 10000);				while (afterDot.length() != 4)				{					afterDot = "0" + afterDot;				}				while ((afterDot.endsWith("0")) && (afterDot.length() > 2))				{					afterDot = afterDot.substring(0, afterDot.length() - 1);				}				costString = costString + afterDot;				return costString;			} else			{				return new String("0.0");			}		} catch (Exception e)		{			return new String("0.0");		}	}	// Extracts the number value from String	public static int decimalToInt(String string)	{		int value = 0;		byte i = 0;		char c = new String(".").charAt(0);		try		{			for (i = 0; i < string.length(); i++)			{				if (c != string.charAt(i))				{					break;				}			}			if (i == string.length() - 1)			{				value = Integer.parseInt(string) * 10000;				return (value);			} else			{				while (c != string.charAt(i))				{					i++;				}				value = Integer.parseInt(string.substring(0, i)) * 10000;				string = string.substring(i + 1, string.length());				while (string.length() > 4)				{					string = string.substring(0, string.length() - 1);				}				while (string.length() < 4)				{					string = string + "0";				}				value = value + Integer.parseInt(string);				return value;			}		} catch (Exception e)		{			return (0);		}	}	//#sijapp cond.end#	// Convert gender code to string	static public String genderToString(int gender)	{		switch (gender)		{		case 1:			return ResourceBundle.getString("female");		case 2:			return ResourceBundle.getString("male");		}		return new String();	}	static public int stringToGender(String gender)	{		if (gender == ResourceBundle.getString("female"))			return 1;		else if (gender == ResourceBundle.getString("male"))			return 2;		return 0;	}	// Converts an Unicode string into CP1251 byte array	public static byte[] stringToByteArray1251(String s)	{		byte abyte0[] = s.getBytes();		char c;		for (int i = 0; i < s.length(); i++)		{			c = s.charAt(i);			switch (c)			{			case 1025:				abyte0[i] = -88;				break;			case 1105:				abyte0[i] = -72;				break;			/* Ukrainian CP1251 chars section */			case 1168:				abyte0[i] = -91;				break;			case 1028:				abyte0[i] = -86;				break;			case 1031:				abyte0[i] = -81;				break;			case 1030:				abyte0[i] = -78;				break;			case 1110:				abyte0[i] = -77;				break;			case 1169:				abyte0[i] = -76;				break;			case 1108:				abyte0[i] = -70;				break;			case 1111:				abyte0[i] = -65;				break;			/* end of section */			default:				char c1 = c;				if (c1 >= '\u0410' && c1 <= '\u044F')				{					abyte0[i] = (byte) ((c1 - 1040) + 192);				}				break;			}		}		return abyte0;	}	// Converts an CP1251 byte array into an Unicode string	public static String byteArray1251ToString(byte abyte0[], int i, int j)	{		StringBuffer stringbuffer = new StringBuffer(j);		int l;		for (int k = 0; k < j; k++)		{			l = abyte0[k + i] & 0xff;			try			{				switch (l)				{				case 168:					stringbuffer.append('\u0401');					break;				case 184:					stringbuffer.append('\u0451');					break;				/* Ukrainian CP1251 chars section */				case 165:					stringbuffer.append('\u0490');					break;				case 170:					stringbuffer.append('\u0404');					break;				case 175:					stringbuffer.append('\u0407');					break;				case 178:					stringbuffer.append('\u0406');					break;				case 179:					stringbuffer.append('\u0456');					break;				case 180:					stringbuffer.append('\u0491');					break;				case 186:					stringbuffer.append('\u0454');					break;				case 191:					stringbuffer.append('\u0457');					break;				/* end of section */				default:					if (l >= 192 && l <= 255)					{						stringbuffer.append((char) ((1040 + l) - 192));					} else					{						stringbuffer.append((char)(l&0xFF));					}					break;				}			}			catch (Exception e)			{				stringbuffer.append('?');			}		}				return stringbuffer.toString();	}	/*/////////////////////////////////////////////////////////////////////////	 //                                                                       //	 //                 METHODS FOR DATE AND TIME PROCESSING                  //	 //                                                                       //		 /////////////////////////////////////////////////////////////////////////*/	private final static String error_str = "***error***";	final public static int TIME_SECOND = 0;	final public static int TIME_MINUTE = 1;	final public static int TIME_HOUR = 2;	final public static int TIME_DAY = 3;	final public static int TIME_MON = 4;	final public static int TIME_YEAR = 5;	final private static byte[] dayCounts = explodeToBytes(			"31,28,31,30,31,30,31,31,30,31,30,31", ',', 10);	/* Creates current date (GMT or local) */	public static long createCurrentDate(boolean gmt)	{	    // getTime() returns GTM time	    long result = new Date().getTime() / 1000;	    /* convert result to GMT time */	    long diff = Options.getInt(Options.OPTION_LOCAL_OFFSET);	    result += (diff * 3600);	    /* returns GMT or local time */	    return gmt ? result : gmtTimeToLocalTime(result);	}	/* Show date string */	public static String getDateString(boolean onlyTime, long date)	{		if (date == 0)			return error_str;		int[] loclaDate = createDate(date);		StringBuffer sb = new StringBuffer();		if (!onlyTime)		{			sb.append(Util.makeTwo(loclaDate[TIME_DAY])).append('.').append(					Util.makeTwo(loclaDate[TIME_MON])).append('.').append(					loclaDate[TIME_YEAR]).append(' ');		}		sb.append(Util.makeTwo(loclaDate[TIME_HOUR])).append(':').append(				Util.makeTwo(loclaDate[TIME_MINUTE]));		return sb.toString();	}	/* Show time string */	public static String getTimeString(long date)	{		if (date == 0)			return error_str;		int[] loclaDate = createDate(date);		StringBuffer sb = new StringBuffer();		sb.append(Util.makeTwo(loclaDate[TIME_HOUR])).append(':').append(				Util.makeTwo(loclaDate[TIME_MINUTE])).append(':')			  .append(Util.makeTwo(loclaDate[TIME_SECOND]));		return sb.toString();	}	/* Generates seconds count from 1st Jan 1970 till mentioned date */	public static long createLongTime(int year, int mon, int day, int hour,			int min, int sec)	{		int day_count, i, febCount;		day_count = (year - 1970) * 365 + day;		day_count += (year - 1968) / 4;		if (year >= 2000)			day_count--;		if ((year % 4 == 0) && (year != 2000))		{			day_count--;			febCount = 29;		} else			febCount = 28;		for (i = 0; i < mon - 1; i++)			day_count += (i == 1) ? febCount : dayCounts[i];		return day_count * 24L * 3600L + hour * 3600L + min * 60L + sec;	}	// Creates array of calendar values form value of seconds since 1st jan 1970 (GMT)	public static int[] createDate(long value)	{		int total_days, last_days, i;		int sec, min, hour, day, mon, year;		sec = (int) (value % 60);		min = (int) ((value / 60) % 60); // min		value -= 60 * min;		hour = (int) ((value / 3600) % 24); // hour		value -= 3600 * hour;		total_days = (int) (value / (3600 * 24));		year = 1970;		for (;;)		{			last_days = total_days					- ((year % 4 == 0) && (year != 2000) ? 366 : 365);			if (last_days <= 0)				break;			total_days = last_days;			year++;		} // year		int febrDays = ((year % 4 == 0) && (year != 2000)) ? 29 : 28;		mon = 1;		for (i = 0; i < 12; i++)		{			last_days = total_days - ((i == 1) ? febrDays : dayCounts[i]);			if (last_days <= 0)				break;			mon++;			total_days = last_days;		} // mon		day = total_days; // day		return new int[]		{ sec, min, hour, day, mon, year };	}	public static String getDateString(boolean onlyTime)	{		return getDateString(onlyTime, createCurrentDate(false));	}	public static String getTimeString()	{		return getTimeString(createCurrentDate(false));	}	public static long gmtTimeToLocalTime(long gmtTime)	{		long diff = Options.getInt(Options.OPTION_GMT_OFFSET);		long dl = Options.getInt(Options.OPTION_DAYLIGHT_SAVING);		return gmtTime + (diff + dl) * 3600L;	}	public static String longitudeToString(long seconds)	{		StringBuffer buf = new StringBuffer();		int days = (int) (seconds / 86400);		seconds %= 86400;		int hours = (int) (seconds / 3600);		seconds %= 3600;		int minutes = (int) (seconds / 60);		if (days != 0)			buf.append(days).append(' ').append(					ResourceBundle.getString("days")).append(' ');		if (hours != 0)			buf.append(hours).append(' ').append(					ResourceBundle.getString("hours")).append(' ');		if (minutes != 0)			buf.append(minutes).append(' ').append(					ResourceBundle.getString("minutes"));		return buf.toString();	}	/*====================================================*/	/*                                                    */	/*                     MD5 stuff                      */	/*                                                    */	/*====================================================*/	static final byte[] AIM_MD5_STRING = explodeToBytes(			"*AOL Instant Messenger (SM)", ',', 16);	static final int S11 = 7;	static final int S12 = 12;	static final int S13 = 17;	static final int S14 = 22;	static final int S21 = 5;	static final int S22 = 9;	static final int S23 = 14;	static final int S24 = 20;	static final int S31 = 4;	static final int S32 = 11;	static final int S33 = 16;	static final int S34 = 23;	static final int S41 = 6;	static final int S42 = 10;	static final int S43 = 15;	static final int S44 = 21;	static final byte[] PADDING = explodeToBytes(			"-128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"					+ "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", ',', 10);	static private long[] state = new long[4];	static private long[] count = new long[2];	static private byte[] buffer = new byte[64];	static private byte[] digest = new byte[16];	static public byte[] calculateMD5(byte[] inbuf)	{		md5Init();		md5Update(inbuf, inbuf.length);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -