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

📄 bbscsutil.java

📁 天乙虚拟社区8.05版本。只支持Mysql
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	public static int boolean2int(boolean value) {
		if (value) {
			return 1;
		} else {
			return 0;
		}
	}

	public static String getClassName(String className, String userID) {
		int num = Math.abs(userID.hashCode());
		className = Constant.BEANPERFIX + className + (num % 10);
		return className;
	}

	public static String getClassName(String className, String userID, int modnum) {
		int num = Math.abs(userID.hashCode());
		className = Constant.BEANPERFIX + className + (num % modnum);
		return className;
	}

	public static String getClassName(String className, long bid, int modnum) {
		className = Constant.BEANPERFIX + className + (bid % modnum);
		return className;
	}

	public static int getTableID(String userID, int num) {
		int absNum = Math.abs(userID.hashCode());
		return (int) (absNum % num);
	}

	public static int getTableID(long bid, int num) {
		return (int) (bid % num);
	}

	public static boolean isAllowPicFile(String fileName) {
		String[] filExts = { "jpg", "jpeg", "gif" };
		return FilenameUtils.isExtension(fileName, filExts);
	}

	public static boolean isPicFile(String fileName) {
		String[] filExts = { "jpg", "jpeg", "gif", "png", "bmp" };
		return FilenameUtils.isExtension(fileName, filExts);
	}

	public static boolean isFlashFile(String fileName) {
		return FilenameUtils.isExtension(fileName, "swf");
	}

	public static long getOnlineInTime() {
		return System.currentTimeMillis() - 180000;
	}

	public static boolean isTodayTime(long atime) {
		Calendar cld = Calendar.getInstance();
		// cld.setTime(new Date());
		int year = cld.get(Calendar.YEAR);
		int month = cld.get(Calendar.MONTH);
		int day = cld.get(Calendar.DAY_OF_MONTH);
		Calendar todaycld = Calendar.getInstance();
		todaycld.set(year, month, day, 0, 0, 0);
		if (atime >= todaycld.getTime().getTime()) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean isLastdayTime(long atime) {
		Calendar cld = Calendar.getInstance();
		// cld.setTime(new Date());
		cld.add(Calendar.DAY_OF_MONTH, -1);
		int year = cld.get(Calendar.YEAR);
		int month = cld.get(Calendar.MONTH);
		int day = cld.get(Calendar.DAY_OF_MONTH);
		Calendar lastdaycld = Calendar.getInstance();
		lastdaycld.set(year, month, day, 0, 0, 0);
		if (atime >= lastdaycld.getTime().getTime()) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean isTodayTime(long atime, String timeZone) {
		return isTodayTime(new Date(atime), timeZone);
	}

	public static boolean isYesterdayTime(long atime, String timeZone) {
		return isYesterdayTime(new Date(atime), timeZone);
	}

	public static boolean isTodayTime(Date atime, String timeZone) {
		Calendar cld = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		cld.set(Calendar.MILLISECOND, 0);
		int nowyear = cld.get(Calendar.YEAR);
		int nowmonth = cld.get(Calendar.MONTH);
		int nowday = cld.get(Calendar.DAY_OF_MONTH);

		Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		c.setTime(atime);
		c.set(Calendar.MILLISECOND, 0);
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day = c.get(Calendar.DAY_OF_MONTH);
		// int second = c.get(Calendar.SECOND);

		if (year == nowyear && month == nowmonth && day == nowday) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean isYesterdayTime(Date atime, String timeZone) {
		Calendar cld = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		cld.set(Calendar.MILLISECOND, 0);
		cld.add(Calendar.DAY_OF_MONTH, -1);
		int yyear = cld.get(Calendar.YEAR);
		int ymonth = cld.get(Calendar.MONTH);
		int yday = cld.get(Calendar.DAY_OF_MONTH);

		Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		c.setTime(atime);
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day = c.get(Calendar.DAY_OF_MONTH);
		// int second = c.get(Calendar.SECOND);

		if (year == yyear && month == ymonth && day == yday) {
			return true;
		} else {
			return false;
		}
	}

	public static String formatDateTime(Date date, String format) {
		SimpleDateFormat outFormat = new SimpleDateFormat(format);
		return outFormat.format(date);
	}

	public static String formatDateTime(Date date, String format, String timeZone) {
		// Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
		// c.setTime(date);
		// c.set(Calendar.MILLISECOND, 0);
		SimpleDateFormat outFormat = new SimpleDateFormat(format);

		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(date.getTime());
		c.set(Calendar.MILLISECOND, 0);
		c.setTimeZone(TimeZone.getTimeZone(timeZone));
		return outFormat.format(c.getTime());
	}

	public static String getFileTypeIcon(String fileExt) {
		String fileTypeIcon = (String) Constant.ICON_MAP.get(fileExt);
		if (fileTypeIcon == null) {
			fileTypeIcon = "default.icon.gif";
		}
		return fileTypeIcon;
	}

	public static String getSpeShortString(String s, int len, String fillstr) {
		int ilen = Math.max(0, len - fillstr.length());
		char ch = ' ';
		int reallen = 0;
		for (int i = 0; i < s.length(); i++) {
			ch = s.charAt(i);
			if (((int) ch > 32) && ((int) ch < 128)) {
				reallen++;
			} else {
				reallen += 2;
			}
		}
		if (reallen <= len) {
			return s;
		}
		StringBuffer buf = new StringBuffer();
		reallen = 0;
		for (int i = 0; i < s.length(); i++) {
			ch = s.charAt(i);
			buf.append(ch);
			if (((int) ch > 32) && ((int) ch < 128)) {
				reallen++;
			} else {
				reallen += 2;
			}
			if (reallen >= ilen) {
				return buf.append(fillstr).toString();
			}
		}
		return buf.toString();
	}

	public static List array2List(String[] ids) {
		List<String> l = new ArrayList<String>();
		if (ids != null) {
			for (int i = 0; i < ids.length; i++) {
				l.add(ids[i]);
			}
		}
		return l;
	}

	public static Locale getLocale(String localeStr) {
		String[] locale_strs = localeStr.split("_");
		if (locale_strs != null && locale_strs.length == 2) {
			return new Locale(locale_strs[0], locale_strs[1]);
		} else {
			return new Locale("zh", "CN");
		}
	}

	public static int id2Int(String id) {
		char[] chars = id.toCharArray();
		int total = 0;
		for (int i = 0; i < chars.length; i++) {
			total += Character.digit(chars[i], 16);
		}
		return total;
	}

	public static List<String> getArchivesMonths(long bid) {
		List<String> l = new ArrayList<String>();
		File archivesMonthsFile = new File(Constant.ROOTPATH + "archives/archivesmonths-" + bid + ".txt");
		String month = "";
		try {
			month = FileUtils.readFileToString(archivesMonthsFile, Constant.CHARSET);
		} catch (IOException e) {
			return l;
		}
		String[] months = month.split(",");
		if (months.length > 0) {
			for (int i = (months.length - 1); i >= 0; i--) {
				if (StringUtils.isNotBlank(months[i])) {
					l.add(months[i]);
				}
			}
		}
		return l;
	}

	public static boolean ArchivesMonthInFile(long bid, String month) {
		List<String> l = getArchivesMonths(bid);
		for (String m : l) {
			if (m.equalsIgnoreCase(month)) {
				return true;
			}
		}
		return false;
	}

	public synchronized static void writeMonthToFile(long bid, String month) {
		File archivesMonthsFile = new File(Constant.ROOTPATH + "archives/archivesmonths-" + bid + ".txt");
		String monthText = "";
		try {
			monthText = FileUtils.readFileToString(archivesMonthsFile, Constant.CHARSET);
		} catch (IOException e) {
			monthText = "";
		}
		if (StringUtils.isBlank(monthText)) {
			monthText = month;
		} else {
			if (monthText.endsWith(",")) {
				monthText = monthText + month;
			} else {
				monthText = monthText + "," + month;
			}
		}
		try {
			FileUtils.writeStringToFile(archivesMonthsFile, monthText, Constant.CHARSET);
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	}

	public static String getArchivesPostMainListPath(long bid, String month) {
		StringBuffer sb = new StringBuffer();
		sb.append(Constant.ROOTPATH);
		sb.append(getArchivesPostMainListWebPath(bid, month));
		File ft = new File(sb.toString());
		if (!ft.exists()) {
			ft.mkdirs();
		}
		return sb.toString();
	}

	public static String getArchivesPostMainListWebPath(long bid, String month) {
		StringBuffer sb = new StringBuffer();
		sb.append("archives/");
		sb.append(bid);
		sb.append("/");
		sb.append(month);
		sb.append("/");
		return sb.toString();
	}

	public static String getArchivesPostTopicPath(long bid, String month, long posttime) {
		StringBuffer sb = new StringBuffer();
		sb.append(Constant.ROOTPATH);
		sb.append(getArchivesPostMainListWebPath(bid, month));
		sb.append(Util.formatDate4(new Date(posttime)));
		sb.append("/");
		sb.append((posttime % 100));
		sb.append("/");
		File ft = new File(sb.toString());
		if (!ft.exists()) {
			ft.mkdirs();
		}
		return sb.toString();
	}

	public static int getStringHashCode(String txt) {
		int t = 0;
		if (txt != null) {
			char[] chars = txt.toCharArray();
			for (int i = 0; i < chars.length; i++) {
				t = t + (int) chars[i];
			}
		}
		return t;
	}

}

⌨️ 快捷键说明

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