SinaburoUtil.java 59.5 KB
Newer Older
Kim Gyeongeun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242
package jp.agentec.sinaburocast.common.util;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JTextArea;

import jp.agentec.sinaburocast.common.SinaburoConstant;
import jp.agentec.sinaburocast.common.SinaburoConstant.Dir;
import jp.agentec.sinaburocast.common.SinaburoConstant.Formats;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.net.util.SubnetUtils;
import org.apache.commons.validator.GenericValidator;
import org.apache.log4j.Logger;
import org.apache.velocity.tools.generic.DateTool;
import org.seasar.framework.util.StringUtil;

/**
 * Utilクラス<br>
 * 主に数値・文字列操作を扱うメソッドを集約<br>
 *
 * ※メソッド追加の際はApache Commons, Seaserのユーティリティクラスに該当の機能が存在しないことをまず確認すること。
 *
 * @author tsukada
 *
 */
public class SinaburoUtil {
	private static final Logger LOGGER = Logger.getLogger(SinaburoUtil.class);

	/**
	 * 配列が空ではないか返す。
	 *
	 * @param objectArray
	 * @return
	 */
	public static boolean isNotEmpty(Object[] objectArray) {
		return !ArrayUtils.isEmpty(objectArray);
	}

	/**
	 * 文字列がブランクかもしくはスペース(全角含む)のみで構成されているか返す。
	 *
	 * @param s
	 * @return
	 *
	 * use {@link StringUtils#isBlank(String)} instead.
	 */
	public static boolean isBlankOrSpace(String s) {
		if (s == null || s.trim().length() == 0) {
			return true;
		}
		else {
			s = StringUtil.replace(s, " ", "");
			s = s.trim();
			return s.length() == 0;
		}
	}

	/**
	 * 文字列がブランクもしくはスペースのみ以外であるか返す。
	 *
	 * @param s
	 * @return
	 *
	 * use {@link StringUtils#isNotBlank(String)} instead.
	 */
	public static boolean isNotBlankOrSpace(String s) {
		return !isBlankOrSpace(s);
	}

	/**
	 * 第一引数がnullもしくはブランクの場合に、第二引数の文字列を返す。
	 *
	 * @param org
	 * @param rep
	 * @return
	 *
	 * LATER If org is an instance of String, use {@link StringUtils#defaultIfEmpty(String, String)} instead.
	 */
	public static String nvl(Object org, String rep) {
		if (org == null || org.toString().length() == 0) {
			return rep;
		}
		else {
			return org.toString();
		}
	}

	/**
	 * nullの場合に、空文字を返す。
	 *
	 * @param org
	 * @return
	 *
	 * LATER If org is an instance of String, use {@link StringUtils#defaultIfEmpty(String, "")} instead.
	 */
	public static String nvl(Object org) {
		return nvl(org, "");
	}

	/**
	 * 空文字の場合、nullを返す。
	 *
	 * @param s
	 * @return
	 */
	public static String toNull(String s) {
		if (StringUtils.isEmpty(s)) {
			return null;
		}
		return s;
	}

	/**
	 * 0の場合に、デフォルト値を返す。
	 *
	 * @param org
	 * @return
	 */
	public static int zvl(int org, int def) {
		if (org == 0) {
			return def;
		}
		return org;
	}

	/**
	 * Integerをintに変換する。<br>
	 * nullの場合0を返す
	 *
	 * @param integer
	 * @return
	 */
	public static int parseInt(Integer integer) {
		if (integer == null) {
			return 0;
		}
		return integer;
	}

	/**
	 * 文字列をshortに変換する。<br>
	 * shortに変換できない場合0を返す。
	 *
	 * @param s
	 * @return
	 *
	 * LATER Apache commonsを2.5以降にバージョンアップすれば廃止できる
	 */
	public static short toShort(String str) {
		short s = 0;
		try {
			s = Short.parseShort(str);
		} catch (Exception e) {}
		return s;
	}

	/**
	 * 文字列を、指定の長さで、指定セパレータで折り返して返却する。<br>
	 * 単語の途中では区切らない。
	 *
	 * @param message 元の文字列
	 * @param maxwidth 一行の長さ
	 * @param separator 行のセパレータ
	 * @return 折り返した文字列
	 */
	public static String wrapLine(String message, int maxwidth, String separator) {
		if (maxwidth < 1) return message;
		if (StringUtils.isEmpty(message)) return "";
		if (separator == null) {
			separator = "";
		}

		// LATER \S, \sの定義はロケールによって変化するが本当でこれでよいのか?
    	Pattern regx = Pattern.compile("(\\S\\S{" + maxwidth + ",}|.{1," + maxwidth + "})(\\s+|$)");
		List<String> list = new LinkedList<String>();
		Matcher m = regx.matcher(message);
		while (m.find()) list.add(m.group());
		return StringUtils.chomp(StringUtils.join(list, separator));
	}

	/**
	 * 文字列を、指定の長さで、指定セパレータで折り返して返却する。<br>
	 * 単語の途中でも折り返す。
	 *
	 * @param message 元の文字列
	 * @param maxwidth 一行の長さ
	 * @param separator 行のセパレータ
	 * @return 折り返した文字列
	 */
	public static String wrapLineNoWord(String message, int maxwidth, String separator) {
		if (StringUtils.isEmpty(message)) return "";
		if (maxwidth < 1) return message;
		if (separator == null) {
			separator = "";
		}

		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < message.length(); i++) {
			sb.append(message.charAt(i));
			if (i != 0 && i % maxwidth == 0) {
				sb.append(separator);
			}

		}
		return StringUtils.chomp(sb.toString());
	}

	/**
	 * バイト表示フォーマットに変換する。<br>
	 * B, K, M, G単位で丸める。<br>
	 *
	 * @param size
	 * @return
	 */
	public static String formatByte(long size){
		if(size/1024 < 1){
			return size + "B";
		}
		else if(size/(1024*1024) < 1){
				return size/1024 + "K";
		}
		else if(size/(1024*1024*1024) < 1){
			return size/(1024*1024) + "M";
		}
		else{
			return size/(1024*1024*1024) + "G";
		}
	}
	/**
	 * 現在値に対して対象bitの値をonまたはoffにする。
	 * (チェックボックス用)
	 *
	 * @param currentVal 現在値
	 * @param targetFlgVal 対象bitの値
	 * @param on オンかどうか
	 * @return
	 */
	public static int mergeBitValue(int currentVal, int targetFlgVal, boolean on) {
		int clearTargetFlg = (currentVal & targetFlgVal) > 0? currentVal - targetFlgVal: currentVal;
		return clearTargetFlg | (on? targetFlgVal:0);
	}


	/**
	 * 引数のStringの中で最初に空でないものを返す。
	 * @param args
	 * @return
	 */
	public static String getFirstNoBlank(String... args) {
		if (args != null) {
			for (String str: args) {
				if (StringUtils.isNotEmpty(str)) {
					return str;
				}
			}
		}
		return "";
	}


	/**
	 * 引数の中で、空ではない個数を返す。
	 *
	 * @param args
	 * @return
	 */
	public static int getNoBlankCount(String... args) {
		int count = 0;
		if (args != null) {
			for (String str: args) {
				if (StringUtils.isNotEmpty(str)) {
					count++;
				}
			}
		}
		return count;
	}

	/**
	 * 第二引数以降の文字列を、第一引数のセパレータで連結して返す。
	 *
	 * @param separator
	 * @param args
	 * @return
	 */
	public static String joinAllNoBlank(String separator, Object... args) {
		if (args == null) return "";
		if (separator == null) separator = "";

		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for (Object obj: args) {
			if (obj == null) {
				obj = "";
			}
			if (StringUtils.isNotEmpty(obj.toString())) {
				if (first) {
					sb.append(obj);
					first = !first;
				}
				else {
					sb.append(separator).append(obj);
				}
			}
		}
		return sb.toString();
	}

	/**
	 * オブジェクトから指定フィールドの値を取り出す。<br>
	 * (リフレクションを用いる)
	 *
	 * @param object
	 * @param fieldName
	 * @return
	 */
	public static Object getFieldValue(Object object, String fieldName) {
		Field field;
		try {
			field = getField(object, fieldName);
			field.setAccessible(true);
			return field.get(object);
		} catch (SecurityException e) {
			LOGGER.error("unable to get field", e);
		} catch (IllegalArgumentException e) {
			LOGGER.error("unable to get field", e);
		} catch (IllegalAccessException e) {
			LOGGER.error("unable to get field", e);
		}
		return null;
	}

	/**
	 * オブジェクトから指定フィールドを取り出す。<br>
	 * (リフレクションを用いる)
	 *
	 * @param object
	 * @param fieldName
	 * @return
	 */
	public static Field getField(Object object, String fieldName) {
		Field field;
		try {
			field = object.getClass().getDeclaredField(fieldName);
			field.setAccessible(true);
			return field;
		} catch (SecurityException e) {
			LOGGER.fatal("unable to get field", e);
		} catch (NoSuchFieldException e) {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("unable to get field: " + fieldName + " of " + object);
			}
		} catch (IllegalArgumentException e) {
			LOGGER.fatal("unable to get field", e);
		}
		return null;
	}

	/**
	 * オブジェクトの指定フィールドに値をセットする。<br>
	 * (リフレクションを用いる)
	 *
	 * @param object
	 * @param fieldName
	 * @return
	 */
	public static void setField(Object object, String fieldName, Object val) {
		Field field;
		try {
			field = object.getClass().getDeclaredField(fieldName);
			field.setAccessible(true);
			field.set(object, val);
		} catch (SecurityException e) {
			LOGGER.fatal("unable to get field", e);
		} catch (NoSuchFieldException e) {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("unable to get field: " + fieldName + " of " + object);
			}
		} catch (IllegalArgumentException e) {
			LOGGER.fatal("unable to get field", e);
		} catch (IllegalAccessException e) {
			LOGGER.fatal("unable to set field", e);
		}
	}

	/**
	 * オブジェクトから指定フィールドの値を取り出す。<br>
	 * (リフレクションを用いる)
	 *
	 * @param object
	 * @param field
	 * @return
	 */
	public static Object getFieldValue(Object object, Field field) {
		try {
			return field.get(object);
		} catch (IllegalArgumentException e) {
			LOGGER.fatal("field get value", e);
		} catch (IllegalAccessException e) {
			LOGGER.fatal("field get value", e);
		}
		return new Object();
	}

	/**
	 * ファイル名から拡張子を取り出す。<br>
	 * 拡張子がない場合空文字を返す。
	 *
	 * @param filename
	 * @return
	 */
	public static String getExtension(String filename) {
		if (StringUtils.isEmpty(filename)) return "";

		int lastIndex = filename.lastIndexOf(".");
		if (lastIndex != -1) {
			return filename.substring(lastIndex + 1);
		}
		else {
			return "";
		}
	}

	/**
	 * 拡張子を除いたファイル名を取り出す。<br>
	 * 拡張子がない場合はそのまま返す。
	 *
	 * @param filename
	 * @return
	 */
	public static String getFilenameWithoutExt(String filename) {
		if (StringUtils.isEmpty(filename)) return "";

		int lastIndex = filename.lastIndexOf(".");
		if (lastIndex != -1) {
			return filename.substring(0, lastIndex);
		}
		else {
		    return filename;
		}
	}

	/**
	 * 呼び出しメソッドを返す。
	 *
	 * @return
	 */
	public static String getCaller() {
		return getCaller(3);
	}

	/**
	 * 呼び出し階層のindex番目のメソッドを返す。<br>
	 * 1番は、このメソッド自体、2番がこのメソッドを呼び出すメソッドとなる。
	 *
	 * @param index
	 * @return
	 */
	public static String getCaller(int index) {
		return new Throwable().getStackTrace()[index].getClassName();
	}

	/**
	 * 正規表現に従ってマッチするかどうかを返す
	 *
	 * @param src
	 * @param regex
	 * @return
	 */
	public static boolean match(String src, String regex) {
		Pattern regx = Pattern.compile(regex);
		Matcher m = regx.matcher(src);
		return m.find();
	}

	/**
	 * 正規表現にしたがって文字列を抽出する
	 *
	 * @param src 対象文字列
	 * @param regex 正規表現
	 * @param index 正規表現中の抽出対象となる()の番号
	 * @return ヒットした最初の文字列
	 */
	public static String extractRegexString(String src, String regex, int index) {
		Pattern regx = Pattern.compile(regex);
		Matcher m = regx.matcher(src);
		if (m.find()) {
			return m.group(index);
		}
		return null;
	}


	/**
	 * 正規表現にしたがって文字列(複数)を抽出する
	 *
	 * @param src 対象文字列
	 * @param regex 正規表現
	 * @param index 正規表現中の抽出対象となる()の番号(配列)
	 * @return ヒットしたすべての文字列リスト
	 */
	@SuppressWarnings("unchecked")
	public static List<List> extractRegexString(String src, String regex, int[] index) {
		Pattern regx = Pattern.compile(regex);
		List<List> list = new LinkedList<List>();
		Matcher m = regx.matcher(src);
		while (m.find()) {
			List<String> matchList = new LinkedList<String>();
			for (int element : index) {
				matchList.add(m.group(element));
			}
			list.add(matchList);
		}
		return list;
	}

	/**
	 * 親のパスを返す(/もしくは\区切り)
	 *
	 * @param name
	 * @return
	 */
	public static String getParentPath(String name) {
		if (StringUtils.isEmpty(name)) return name;

		int index = name.lastIndexOf('/');
		if (index == -1) {
			index = name.lastIndexOf('\\');
		}

		if (index > 0) {
			return name.substring(0, index);
		}
		else {
			return null;
		}
	}

	/**
	 * パスからファイル名を取り出して返す(/もしくは\区切り)
	 *
	 * @param name
	 * @return
	 */
	public static String getFileName(String name) {
		if (StringUtils.isEmpty(name)) return name;

		int index = name.lastIndexOf('/');
		if (index == -1) {
			index = name.lastIndexOf('\\');
		}

		if (index != -1) {
			return name.substring(index + 1);
		}
		else {
			return name;
		}
	}

	/**
	 * 文字列にダブルバイトを含むかどうかを返す。<br>
	 * \を含むものもダブルバイトとみなす。
	 *
	 * @param s
	 * @return
	 */
	public static boolean hasDoubleByte(String s) {
		if (StringUtils.isEmpty(s)) return false;

		if (s.contains("\\")) {
			return true;
		}

		return s.getBytes().length != s.length();
	}

	/**
	 * cygwinのパスからWindowsのパスへ変換する。
	 *
	 * @param path
	 * @param drive ドライブレターを含めるか否か
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static String cygwinToWin(String path, boolean drive) {
		try {
			if (path.contains("\\")) {
				path = StringUtils.replace(path, "\\", "/");
			}

			if (path.startsWith("/cygdrive/")) {
				List list = extractRegexString(path, "/cygdrive/(.)/(.*)", new int[]{1,2});
				List matchList = (List)list.get(0);
				return drive? matchList.get(0) + ":/" + matchList.get(1): "/" + matchList.get(1);
			}
		} catch (Exception e) {
			LOGGER.error("cygwinToWin failed: " + path);
		}
		return path;
	}

	/**
	 * Windowsのパスをcygwinのパスに変換する
	 *
	 * @param path
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static String winToCygwin(String path) {
		try {
			List list = extractRegexString(path, "(.):/(.*)", new int[]{1,2});
			if (list.size() == 0) {
				list = extractRegexString(path, "(.):\\\\(.*)", new int[]{1,2});
			}
			if (list.size() == 0) {
				if (!path.startsWith("/cygdrive/") && path.startsWith("/")){
					return "/cygdrive/c" + path;
				}
				else {
					return path;
				}
			}
			List matchList = (List)list.get(0);
			return "/cygdrive/"+ matchList.get(0) + "/" + StringUtils.replace((String) matchList.get(1), "\\", "/");
		} catch (Exception e) {
			LOGGER.error("cygwinToWin failed: " + path, e);
		}
		return path;
	}

	/**
	 * カレントディレクトリを返す。
	 *
	 * @return
	 */
	public static String getCurrentDirectory() {
		return new File(".").getAbsoluteFile().getParent();
	}

	/**
	 * Linuxパス形式に変換する
	 *
	 * @param path
	 * @return
	 */
	public static String toLinuxPath(String path) {
		String linuxPath = StringUtils.replace(path, Dir.WINDOWS_SEP, Dir.LINUX_SEP);
		int driveIndex = linuxPath.indexOf(":");
		if (driveIndex != -1) {
			linuxPath = linuxPath.substring(driveIndex+ 1);
		}
		return linuxPath;
	}

	/**
	 * Windowsパス形式に変換する
	 *
	 * @param path
	 * @return
	 */
	public static String toWinPath(String path) {
		return StringUtils.replace(path, Dir.LINUX_SEP, Dir.WINDOWS_SEP);
	}

	/**
	 * 文字列をMD5Hash化する
	 *
	 * @param str
	 * @return
	 */
	public static String toMd5Hash(String str) {
		return DigestUtils.md5Hex(str);
	}

	/**
	 * 第一引数の文字列を第二引数の文字列で分解し、空白以外のものを<br>
	 * リストにして返す。
	 *
	 * @param inputStr
	 * @param splitStr
	 * @return
	 */
	public static List<String> stringToListWithoutBlank(String inputStr, String splitStr) {
		List<String> retList = new ArrayList<String>();
		if (StringUtils.isNotEmpty(inputStr)) {
			String[] strArray = inputStr.split(splitStr);
			for (String string : strArray) {
				if (StringUtils.isNotEmpty(string.trim())) {
					retList.add(string.trim());
				}
			}
		}
		return retList;
	}

    /**
     * @param str
     * @param splitStr
     * @return
     */
    public static List<Integer> stringToList(String str, String splitStr){
    	List<Integer> list = new ArrayList<Integer>();
    	if(StringUtils.isNotBlank(str)){
    		String[] strs = str.split(splitStr);
        	for(String id : strs){
        		list.add(new Integer(id));
        	}
    	}
    	return list;
    }

	/**
	 * 空白が含まれるかどうかを返す。
	 *
	 * @param path
	 * @return
	 */
	public static boolean hasSpace(String path) {
		if (StringUtils.isEmpty(path)) return false;
		return path.contains(" ");
	}

	/**
	 * スラッシュが含まれるかどうかを返す。
	 *
	 * @param val
	 * @return
	 */
	public static boolean hasSlash(String val) {
		if (StringUtils.isEmpty(val)) return false;
		return val.contains("/");
	}

	/**
	 * Leftパディング<br>
	 * numをpadStrでパディングした文字列を返します。<br>
	 * num > sizeの場合はnumを文字列変換した値を返却します。
	 * @param num
	 * @param size
	 * @param padStr
	 * @return
	 */
	public static String leftPad(long num, int size, String padStr){
		String str = Long.toString(num);
		if (str.length() > size) {
			return Long.toString(num);
		}
		return StringUtils.leftPad(Long.toString(num), size, padStr);
	}

	/**
	 * 現在日時を返却します
	 * @return 現在日時
	 */
	public static Timestamp getTimestamp(){
		return new Timestamp(System.currentTimeMillis());
	}

	/**
	 * String文字列をTimestamp型に変換します。<br>
	 * 変換時例外が発生した場合はnullを返却します。
	 * @param time 文字列
	 * @param format ハイフン区切りフォーマット
	 * @return Timestamp
	 */
	public static Timestamp convertStringToTimestamp(String time, String format){

		time = time.replaceAll("/", "-");

		try {
			return new Timestamp(new SimpleDateFormat(format).parse(time).getTime());
		} catch (ParseException e) {
			return null;
		}

	}

	/**
	 * String配列をInteger配列に変換して返却します。
	 * 変換時エラーはnullを返却します。
	 * @param strList String配列
	 * @return Integer配列
	 */
	public static Integer[] changeStringToInteger(String[] strList){
		Integer[] intList = new Integer[strList.length];
		try {
			for (int i=0; i<strList.length; i++) {
				intList[i] = Integer.parseInt(strList[i]);
			}
		} catch (NumberFormatException e) {
			return null;
		}
		return intList;
	}

	/**
	 * 指定日付のDateを返す。
	 *
	 * @param year
	 * @param month
	 * @param day
	 * @return
	 */
	public static Date getDate(int year, int month, int day) {
		return getDate(year, month, day, 0, 0, 0);
	}

	/**
	 * 指定日付のDateを返す。
	 *
	 * @param year
	 * @param month
	 * @param day
	 * @return
	 */
	public static Date getDate(String year, String month, String day) {

		return getDate(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day), 0, 0, 0);
	}
	/**
	 * 指定日時のDateを返す。
	 *
	 * @param year
	 * @param month
	 * @param day
	 * @param hour
	 * @param minute
	 * @param second
	 * @return
	 */
	public static Date getDate(int year, int month, int day, int hour, int minute, int second) {
		Calendar c = Calendar.getInstance();
		c.set(year, month - 1, day, hour, minute, second);
		return c.getTime();
	}

	public static Timestamp getAddSecond(Date date, int hour) {
		return getAddDate(date, hour, Calendar.SECOND);
	}

	/**
	 * 指定日から時間を加減する。
	 * @param date
	 * @param hour
	 * @return
	 */
	public static Timestamp getAddHour(Date date, int hour) {
		return getAddDate(date, hour, Calendar.HOUR);
	}

	/**
	 * 指定日から日数を加減する。
	 * @param date
	 * @param day
	 * @return
	 */
	public static Timestamp getAddDate(Date date, int day) {
		return getAddDate(date, day, Calendar.DATE);
	}

	public static Timestamp getAddDate(Date date, int value, int calendarType) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(calendarType, value);
		return new Timestamp(c.getTimeInMillis());
	}

	//public static Date getAddDate()


	/**
	 * TimestampからYYYY/MM/DD文字列に変換します
	 * @param insertDate
	 * @return
	 */
	public static String dateDispFormat(Timestamp insertDate){
		if (null == insertDate) {
			return null;
		}
		return new SimpleDateFormat(Formats.DATATYPE_DATE_FORMAT).format(insertDate.getTime());
	}

	/**
	 * 今日のYYYYMMDD文字列に変換します
	 * @return   ex) 20120829
	 */
	public static String getToDayString(){

		return new SimpleDateFormat(Formats.DATATYPE_DATE_FORMAT_NON_SLASH).format(new Timestamp(System.currentTimeMillis()).getTime());
	}

	/**
	 * 引数searchに一致するclazzクラスのメンバ名を全て返却します。<br>
	 * Pattern・Matcherを使用しているため、引数searchは正規表現可となります。
	 * @param search
	 * @return
	 */
	public static List<String> getFieldNames(Class<?> clazz, String search){
		String[] allNames = getFieldNames(clazz);
		List<String> resultList = new ArrayList<String>();
		Pattern p = Pattern.compile(search);
		for (String allName : allNames) {
			Matcher m = p.matcher(allName);
			if (m.matches()) {
				resultList.add(allName);
			}
		}
		return resultList;
	}

	/**
	 * 引数 clazzクラスのメンバ名を全て返却します。
	 * @param clazz
	 * @return
	 */
	public static String[] getFieldNames(Class<?> clazz){
		Field[] fields = clazz.getFields();
		String[] names = new String[fields.length];
		for (int i=0; i<fields.length;i++) {
			names[i] = fields[i].getName();
		}
		return names;
	}

	/**
	* 半角カナチェック<br>
	* 引数の文字列に半角カナが含まれている場合にはtrueを返します。
	* @param String str 検索文字列
	* @return boolean true:半角カナ, false:半角カナ以外もあり
	*/
	public static boolean isHankakuKana(String str) {

		if (StringUtils.isNotEmpty(str)) {
			char[] chars = str.toCharArray();

			for (char target : chars) {
				if (0xff61 <= target && target <= 0xff9f) {
					return true;
				}
			}
		}
		return false;
	}

	/**
	* 全角→半角変換<br>
	* 引数の文字列に全角英数字が含まれている場合には半角に変換して返します。
	* @param String 検索文字列
	* @return String
	*/
	public static String getZenkakuToHankaku(String value, int flg) {
	    StringBuilder sb = new StringBuilder(value);
	    for (int i = 0; i < sb.length(); i++) {
	        int c = (int) sb.charAt(i);
	        if ((c >= 0xFF10 && c <= 0xFF19) || (c >= 0xFF21 && c <= 0xFF3A) || (c >= 0xFF41 && c <= 0xFF5A)) {
	            sb.setCharAt(i, (char) (c - 0xFEE0));
	        }

	        //"、", " "全角→半角
	        if( flg == 1 ){
	        	if (sb.charAt(i) == ' ') {
		            sb.setCharAt(i, ' ');
		        }else if( sb.charAt(i) == '、') {
		        	sb.setCharAt(i, ',');
		        }
	        }
	    }
	    value = sb.toString();
	    return value;
	}

	/**
	* 半角カナ→全角カナ変換<br>
	* @param String 検索文字列
	* @return String
	*/
	public static String getHankanaToZenKana(String s) {

        HashMap<String,String> hmCharTbl = new HashMap<String,String>();

        hmCharTbl.put("ア", "ア");
        hmCharTbl.put("イ", "イ");
        hmCharTbl.put("ウ", "ウ");
        hmCharTbl.put("エ", "エ");
        hmCharTbl.put("オ", "オ");
        hmCharTbl.put("カ", "カ");
        hmCharTbl.put("キ", "キ");
        hmCharTbl.put("ク", "ク");
        hmCharTbl.put("ケ", "ケ");
        hmCharTbl.put("コ", "コ");
        hmCharTbl.put("サ", "サ");
        hmCharTbl.put("シ", "シ");
        hmCharTbl.put("ス", "ス");
        hmCharTbl.put("セ", "セ");
        hmCharTbl.put("ソ", "ソ");
        hmCharTbl.put("タ", "タ");
        hmCharTbl.put("チ", "チ");
        hmCharTbl.put("ツ", "ツ");
        hmCharTbl.put("テ", "テ");
        hmCharTbl.put("ト", "ト");
        hmCharTbl.put("ナ", "ナ");
        hmCharTbl.put("ニ", "ニ");
        hmCharTbl.put("ヌ", "ヌ");
        hmCharTbl.put("ネ", "ネ");
        hmCharTbl.put("ノ", "ノ");
        hmCharTbl.put("ハ", "ハ");
        hmCharTbl.put("ヒ", "ヒ");
        hmCharTbl.put("フ", "フ");
        hmCharTbl.put("ヘ", "ヘ");
        hmCharTbl.put("ホ", "ホ");
        hmCharTbl.put("マ", "マ");
        hmCharTbl.put("ミ", "ミ");
        hmCharTbl.put("ム", "ム");
        hmCharTbl.put("メ", "メ");
        hmCharTbl.put("モ", "モ");
        hmCharTbl.put("ヤ", "ヤ");
        hmCharTbl.put("ユ", "ユ");
        hmCharTbl.put("ヨ", "ヨ");
        hmCharTbl.put("ラ", "ラ");
        hmCharTbl.put("リ", "リ");
        hmCharTbl.put("ル", "ル");
        hmCharTbl.put("レ", "レ");
        hmCharTbl.put("ロ", "ロ");
        hmCharTbl.put("ワ", "ワ");
        hmCharTbl.put("ヲ", "ヲ");
        hmCharTbl.put("ン", "ン");
        hmCharTbl.put("ァ", "ァ");
        hmCharTbl.put("ィ", "ィ");
        hmCharTbl.put("ゥ", "ゥ");
        hmCharTbl.put("ェ", "ェ");
        hmCharTbl.put("ォ", "ォ");
        hmCharTbl.put("ッ", "ッ");
        hmCharTbl.put("ャ", "ャ");
        hmCharTbl.put("ュ", "ュ");
        hmCharTbl.put("ョ", "ョ");
        hmCharTbl.put("ー", "ー");
        hmCharTbl.put("。", "。");
        hmCharTbl.put("、", "、");
        hmCharTbl.put("・", "・");
        hmCharTbl.put("「", "「");
        hmCharTbl.put("」", "」");
        hmCharTbl.put("゙", "゛");
        hmCharTbl.put("゚", "゜");
        hmCharTbl.put("ヴ", "ヴ");
        hmCharTbl.put("ガ", "ガ");
        hmCharTbl.put("ギ", "ギ");
        hmCharTbl.put("グ", "グ");
        hmCharTbl.put("ゲ", "ゲ");
        hmCharTbl.put("ゴ", "ゴ");
        hmCharTbl.put("ザ", "ザ");
        hmCharTbl.put("ジ", "ジ");
        hmCharTbl.put("ズ", "ズ");
        hmCharTbl.put("ゼ", "ゼ");
        hmCharTbl.put("ゾ", "ゾ");
        hmCharTbl.put("ダ", "ダ");
        hmCharTbl.put("ヂ", "ヂ");
        hmCharTbl.put("ヅ", "ヅ");
        hmCharTbl.put("デ", "デ");
        hmCharTbl.put("ド", "ド");
        hmCharTbl.put("バ", "バ");
        hmCharTbl.put("ビ", "ビ");
        hmCharTbl.put("ブ", "ブ");
        hmCharTbl.put("ベ", "ベ");
        hmCharTbl.put("ボ", "ボ");
        hmCharTbl.put("パ", "パ");
        hmCharTbl.put("ピ", "ピ");
        hmCharTbl.put("プ", "プ");
        hmCharTbl.put("ペ", "ペ");
        hmCharTbl.put("ポ", "ポ");

        StringBuffer sbBuf = new StringBuffer();
        String  strKey = "";  // HashMapのKEY
        String  strChar1 = "";          // 1文字目
        char    c1 = ' ';               // 1文字目
        char    c2 = ' ';               // 2文字目
        int     i;
        for (i=0; i<s.length(); i++) {

            c1 = ' ';
            c2 = ' ';
            c1 = s.charAt(i);
            if ((i+1) < s.length()) {
                c2 = s.charAt(i+1);
            }

            strChar1 = "";
            if (c2 == '゙' || c2 == '゚') {
                strKey = String.valueOf(c1) + String.valueOf(c2);
                strChar1 = (String)hmCharTbl.get(strKey);
                if (strChar1 == null) {
                    strKey = String.valueOf(c1);
                    strChar1 = (String)hmCharTbl.get(strKey);
                    if (strChar1 == null) {
                        sbBuf.append(c1);
                    } else {
                        sbBuf.append(strChar1);
                    }
                } else {
                    sbBuf.append(strChar1);
                    i++;
                }
            } else {
                strKey = String.valueOf(c1);
                strChar1 = (String)hmCharTbl.get(strKey);
                if (strChar1 == null) {
                    sbBuf.append(c1);
                } else {
                    sbBuf.append(strChar1);
                }
            }
        }
        return sbBuf.toString();
    }


	/**
	 * String文字列をDate型に変換して返却します。<br>
	 * 変換できなかった場合はParseExceptionをthrowします。
	 * ex) "2010/06/15" → 変換OK
	 *     "2010-06-15" → 変換NG
	 *     "20100615"   → 変換NG
	 * @param dateStr
	 * @return
	 * @throws ParseException
	 */
	public static Date stringToDateSlash(String dateStr){

		Date  date = null;
		try{
			date = DateFormat.getDateInstance().parse(dateStr);
		}catch (Exception e) {
			LOGGER.error(e,e);
			return null;
		}
		return date;
	}

	/**
	 * Timestamp型を文字列に変換します。<br>
	 * 変換時例外が発生した場合はnullを返却します。
	 * @param time Timestamp
	 * @param format 文字列
	 * @return Timestamp
	 */
	public static String convertTimestampToString(Timestamp time, String dateformat){
		return new SimpleDateFormat(dateformat).format(time);
	}

	/**
	 * Date型を文字列に変換します。<br>
	 * 変換時例外が発生した場合はnullを返却します。
	 * @param time Date
	 * @param format フォーマット
	 * @return String
	 */
	public static String convertTimestampToString(Date time, String dateformat){
		return new SimpleDateFormat(dateformat).format(time);
	}

	/**
	 * 現在日時を指定フォーマットで返します。
	 *
	 * @param dateformat
	 * @return
	 */
	public static String getTimeStringAs(String dateformat){
		return new SimpleDateFormat(dateformat).format(getTimestamp());
	}


	/**
	 * 第一引数に、第二引数以降のいずれかが一致した場合trueを返す
	 *
	 * @param s
	 * @param targets
	 * @return
	 */
	public static boolean equalsAny(String s, String... targets) {
		for (String target : targets) {
			if (s.equals(target)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * SQLのlike検索用に「keywordを含む任意の文字列」にマッチするパターンを作成する.
	 *
	 * キーワード自体にワイルドカードが含まれていた場合はエスケープする。
	 *
	 * <em>PostgreSQL用。別のRDBMSにはおそらく別のメソッドが必要。</em>
	 * PostgreSQLのワイルドカードは _, %の2種。
	 * エスケープ文字は設定で変更可能だがデフォルトでは \
	 */
	private static String makeLikePattern_PostgreSQL(String keyword) {
		final int length = keyword.length();
		StringBuilder sb = new StringBuilder(length + 2);
		sb.append('%');
		for (int i = 0 ; i < length ; i++ ) {
			switch (keyword.charAt(i)) {
			case '%':
			case '_':
			case '\\':
				sb.append('\\');
				/* don't break */
			default:
				sb.append(keyword.charAt(i));
			}
		}
		sb.append('%');

		return	sb.toString();
	}

	/**
	 * SQLのlike検索用に「keywordを含む任意の文字列」にマッチするパターンを作成する.
	 *
	 * キーワード自体にワイルドカードが含まれていた場合はエスケープする。
	 *
	 * LATER:arima: 今のところPostgreSQL用しか実装していない
	 */
	public static String makeLikePattern(String keyword) {
		if (keyword == null)	return	null;
		if (keyword.isEmpty())	return	"";

		return	makeLikePattern_PostgreSQL(keyword);
	}

	/**
	 * 日数を加減する。
	 *
	 * @param days
	 * @return Timestampのタイプ
	 */
	public static Timestamp addDate(int days) {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, days);

		return new Timestamp(cal.getTime().getTime());
	}

	/**
	 * 分を加減する。
	 *
	 * @param mins
	 * @return Timestampのタイプ
	 */
	public static Timestamp addMin(int mins) {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MINUTE, mins);

		return new Timestamp(cal.getTime().getTime());
	}

	/**
	 * 月数を加減する。
	 *
	 * @param months
	 * @return Timestampのタイプ
	 */
	public static Timestamp addMonth(int months) {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MONTH, months);

		return new Timestamp(cal.getTime().getTime());
	}

	/**
	 * disk容量を表示単位で計算(MB,GB,TB)
	 * @param diskvolume disk容量
	 * @return disk容量
	 */
	public static String calculateDiskVolume(Long diskVolume) {
		if (diskVolume == null) {
			return "0Byte";
		}
		//KB
		BigDecimal kb = new BigDecimal(1024L);
		//MB
		BigDecimal mb = new BigDecimal(1048576L);
		//GB
		BigDecimal gb = new BigDecimal(1073741824L);
		//TB
		BigDecimal tb = new BigDecimal(1099511627776L);

		//Byte
		if (diskVolume < 1000L) {
			return diskVolume + "Byte";
		}

		//KB
		if (diskVolume < 1000000L) {
			BigDecimal diskvDecimal = new BigDecimal(diskVolume);
			return diskvDecimal.divide(kb, 2, BigDecimal.ROUND_HALF_UP).doubleValue() + "KB";
		}

		//MB
		if (diskVolume < 1000000000L) {
			BigDecimal diskvDecimal = new BigDecimal(diskVolume);
			return diskvDecimal.divide(mb, 2, BigDecimal.ROUND_HALF_UP).doubleValue() + "MB";
		}

		//GB
		if (diskVolume < 1000000000000L) {
			BigDecimal diskvDecimal = new BigDecimal(diskVolume);
			return diskvDecimal.divide(gb, 2, BigDecimal.ROUND_HALF_UP).doubleValue() + "GB";
		}
		//TB
		BigDecimal diskvDecimal = new BigDecimal(diskVolume);
		return diskvDecimal.divide(tb, 2, BigDecimal.ROUND_HALF_UP).doubleValue() + "TB";
	}

	/**
	 * リストの各要素を型チェックしてキャスト
	 * @param <E>
	 * @param list
	 * @return 各要素がEであることが型保証されたリスト
	 */
	@SuppressWarnings("unchecked")
	public static <E> List<E> castList(List<?> list, Class<E> type) {
		for (Object obj : list) {
			if (type.isInstance(obj) || obj == null) continue;

			throw new ClassCastException("object[" + obj + "][" + obj.getClass() + "] is not element type[" + type + "]");
		}

		return (List<E>)list;
	}

	private static String ELLIPSIS = "...";
	private static String NBSP = "&nbsp;";

	/**
	 * 文字列長が指定したmaxlengthを越えないように適宜省略する
	 * @param str 表示される文字列
	 * @param maxlength 許容される最大長
	 * @return
	 */
	public static String getBrief(String str, final int maxlength) {
		/* パラメータ補正 */
		if (str == null)	str = "";
		if (maxlength < ELLIPSIS.length()) {
			/* ワーストケースでは ... となるため最低3文字必要 */
			throw new IllegalArgumentException("maxlength is too small");
		}

		final int len = str.length();
		if (len <= maxlength) {
			return	str;
		} else if (len > ELLIPSIS.length()) {
			return	str.substring(0, maxlength - ELLIPSIS.length()) + ELLIPSIS;
		} else {
			return	ELLIPSIS;
		}
	}

	/**
	 * 2つの文字列を一行に並べて表示する。その際、合計の文字列長が指定したmaxlengthを越えないように適宜省略する
	 * @param str1 左側に表示される文字列
	 * @param str2 右側に表示される文字列
	 * @param maxlength 許容される最大長
	 * @return
	 */
	public static String getBrief2(String str1, String str2, final int maxlength) {
		/* パラメータ補正 */
		if (str1 == null)	str1 = "";
		if (str2 == null)	str2 = "";
		if (maxlength < ELLIPSIS.length() * 2) {
			/* ワーストケースでは ... ... となるため最低6文字必要 */
			throw new IllegalArgumentException("maxlength is too small");
		}

		final int len1 = str1.length();
		final int len2 = str2.length();
		if (len1 + len2 > maxlength) {
			final int len_overflow = len1 + len2 - maxlength + ELLIPSIS.length();
			if (len1 >= len_overflow) {
				/* str1のみ短縮すればよい */
				str1 = str1.substring(0, len1 - len_overflow) + ELLIPSIS;
			} else if (len2 >= len_overflow) {
				/* str2のみ短縮すればよい */
				str2 = str2.substring(0, len2 - len_overflow) + ELLIPSIS;
			} else {
				/* 双方とも短縮が必要 */
				final int targetlength = maxlength / 2 - ELLIPSIS.length();
				str1 = len1 > targetlength
					? str1.substring(0, targetlength) + ELLIPSIS
					: ELLIPSIS;
				str2 = len2 > targetlength
					? str2.substring(0, targetlength) + ELLIPSIS
					: ELLIPSIS;
			}
		}

		return	str1 + NBSP + str2;
	}

	public static boolean containsLast(List<String> list, String target) {
		if (CollectionUtils.isEmpty(list) || StringUtil.isEmpty(target)) {
			return false;
		}

		for (String str : list) {
			if (!str.isEmpty() && target.endsWith(str)) {
				return true;
			}
		}
		return false;
	}


	/**
	 * ビット演算でvalがtarget値を含む場合true
	 *
	 * @param val
	 * @param target
	 * @return
	 */
	public static boolean include(Integer val, Integer target) {
		if (val == null || target == null) return false;
		return (val & target) == target;
	}

	// isHexメソッド用
	private static Pattern regxHexStr = Pattern.compile("^[0-9a-fA-F]+$");
	/**
	 * 引数が16進数かどうか返す。
	 * Long.parseLong(str, 16)は使わない
	 *
	 * @param str
	 * @return
	 */
	public static boolean isHex(String str) {
		try {
			Matcher m = regxHexStr.matcher(str);
			return m.find();
		} catch (Exception e) {
			return false;
		}
	}

	/**
	 * 第一引数strが空でなければ、str + sep、空であれば空文字を返す。
	 *
	 * @param str
	 * @param sep
	 * @return
	 */
	public static String prepend(String str, String sep) {
		return StringUtils.isNotEmpty(str)? str + sep: "";
	}

	/**
	 * 配列から""を削除
	 * @param strs
	 * @return
	 */
	public static String[] deleteNullStringForArray(String[] strs) {
		List<String> list = new ArrayList<String>();
		for (String  str : strs) {
			if (StringUtils.isNotBlank(str)) {
				list.add(str);
			}
		}
		return list.toArray(new String[list.size()]);
	}

	/**
	 * 分の最後を0にする。ex)49分→40分
	 * @param mm
	 * @return
	 */
	public static String convertMinute(String mm) {
		return StringUtils.left(mm, 1) + "0";
	}

	/**
	 * strにnum文字同じ文字が連続して含まれるか
	 *
	 * @return
	 */
	public static boolean hasSeqChar(String str, int num) {
		int count = 0;
		char prev = 0;

		for (int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if (i > 0 && prev == c) {
				count++;
				if (count == num - 1) {
					return true;
				}
			}
			else {
				count = 0;
			}
			prev = c;
		}

		return false;
	}

	/**
	 * str1に、str2と同じ連続したnum文字が含まれるか
	 *
	 * @param str2
	 * @return
	 */
	public static boolean containSameSeqChar(String str1, String str2, int num) {
		if (str2.length() < num || str1.length() < num) {
			return false;
		}

		for (int i = 0; i <= str2.length() - num; i++) {
			String target = str2.substring(i, i + num);
			if (str1.contains(target)) {
				return true;
			}
		}

		return false;
	}

	/**
	 * アルファベットと数字両方を含むか
	 *
	 * @param str
	 * @return
	 */
	public static boolean hasBothAlphaDigit(String str) {
		return SinaburoUtil.match(str, "[0-9]") && SinaburoUtil.match(str, "[a-zA-Z]");
	}

	/**
	 * classesディレクトリの絶対パスを返す
	 *
	 * @return
	 */
	public static String getClassesPath() {
		return StringUtils.substringBefore(SinaburoUtil.class.getResource("SinaburoUtil.class").getFile(), "/jp/");
	}

	/**
	 * 文字列実体参照を置換する
	 * @param value
	 * @return
	 */
	public static String charEntityReferenceReplacement(String value) {
		if (value == null) {
			return value;
		}

		StringBuffer buff = new StringBuffer();
		for (int i = 0; i < value.length(); i++) {
			switch (value.charAt(i)) {
			case '<' :
				buff.append("&lt;");
			    break;
			case '>' :
				buff.append("&gt;");
			    break;
			case '&' :
				if (i + 1 <= value.length() - 1 && value.charAt(i + 1) == '#') {
					buff.append('&');
				} else {
					buff.append("&amp;");
				}
				break;
//			case '"' :
//				buff.append("&quot;");
//			    break;
//			case '\'' :
//				buff.append("&#39;");
//			    break;
			default :
			    buff.append(value.charAt(i));
			    break;
			}
		}

		return buff.toString();
	}

	public static boolean isIp4Address(String remoteAddr) {
		if (remoteAddr == null) {
			return false;
		}
		return match(remoteAddr, "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
	}

	/**
	 * 携帯メールアドレスチェック
	 *
	 * @param str
	 * @return true:携帯メール、false:PCメール
	 */
	public static boolean mobileAddressCheck(String mailAddress) {
		if(StringUtil.isBlank(mailAddress)) {
			return true;
		}

		// TODO: 	PropertyUtil.getPropertiesStartWith("MOBILE.")で書き換え
		if (mailAddress.matches(PropertyUtil.getProperty("MOBILE.AU"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.AU.COM"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.DOCOMO"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.VODAFONE"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.SOFTBANK"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.PDX"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.PDX2"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.PDX3"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.PDX4"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.PDX5"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.DOCOMO.CAMERA"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.MOPERA"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.DWMAIL"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.IDO"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.DESNEY"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.I.SOFTBANK"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.WILLCOM"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.EMNET"))
				|| mailAddress.matches(PropertyUtil.getProperty("MOBILE.VERTUCLUB"))) {
			return true;
		}
		return false;
	}

	/**
	 * Date型を文字列に変換します。<br>
	 * 変換時例外が発生した場合はnullを返却します。
	 * @param String DATE
	 * @param format 文字列
	 * @return Timestamp
	 * @throws ParseException
	 */
	public static String convertStringDateToFormat(String date, String dateformat) {
		if (date == null) {
			return null;
		}
		date = date.substring(0, 4)+dateformat+date.substring(4, 6)+dateformat+date.substring(6, 8);

		return date;
	}

	public static String convertStringTimeToFormat(String date, String dateformat) {
		if (date == null) {
			return null;
		}
		date = date.substring(0, 4)+dateformat+date.substring(4, 6)+dateformat+date.substring(6, 8)+" "
				+ date.substring(8, 10)+":"+date.substring(10, 12)+":"+date.substring(12, 14);

		return date;
	}


    public static String addhyphenDate(String arg){
    	if(arg == null){
    		return arg;
    	}
    	String val = arg;

    	if (arg.length() == 8) {
    		val =  convertStringDateToFormat(arg, "-");
    	}
    	if (arg.length() == 6) {
    		val =  convertStringDateToFormat2(arg, "-");
    	}
    	return val;
    }

	/**
	 * Date型を文字列に変換します。<br>
	 * 変換時例外が発生した場合はnullを返却します。
	 * @param String DATE
	 * @param format 文字列
	 * @return Timestamp
	 * @throws ParseException
	 */
	public static String convertStringDateToFormat2(String date, String dateformat) {
		if (date == null) {
			return null;
		}
		date = date.substring(0, 4)+dateformat+date.substring(4, 6);

		return date;
	}
	/**
	 * "0"をつめる<br>
	 * @param String str
	 * @param int length
	 * @return str
	 */
	public static String  LeftPadZero (String str, int value) {
		if (str.length() == value || str.length() == 0) {
			return str;
		} else {
			for (int i = 1; i < value; i++) {
				str = "0"+str;
			}
		}
		return str;
	}

	/**
	 * argsの中にsrcが存在していたらtrue
	 * @param src
	 * @param args
	 * @return argsの存在していたらtrue
	 */
	public static boolean contain(Object src ,Object... args ){

		for(int i=0;i < args.length;i++){
			if(src.toString().equals(args[i].toString())){
				return true;
			}
		}
		return false;
	}

	/**
	 * 入力されたurlのhtml文字列を戻す。
	 * @param url
	 * @return
	 */
	public static String getHtml(URL url){

		String charset = "UTF-8";
		JTextArea htmlArea = htmlArea = new JTextArea();
        // Webページを読み込む
        try {
            // 接続
            URLConnection uc = url.openConnection();
            // HTMLを読み込む
            BufferedInputStream bis = new BufferedInputStream(uc.getInputStream());
            BufferedReader br = new BufferedReader(new InputStreamReader(bis, charset));
            htmlArea.setText("");//初期化
            String line;
            while ((line = br.readLine()) != null) {
                htmlArea.append(line + SinaburoConstant.newLine.N);
            }
        } catch (MalformedURLException ex) {
            htmlArea.setText("URLが不正です。");
            ex.printStackTrace();
        } catch (UnknownHostException ex) {
            htmlArea.setText("サイトが見つかりません。");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        return htmlArea.getText();
    }


	public static void writeFile(String filePath,String content,String chaString)throws Exception{
		  String charset = "UTF-8";
		  if(chaString == null  )chaString = charset;

		  FileOutputStream fos = new FileOutputStream(filePath);
		  OutputStreamWriter osW = new OutputStreamWriter(fos, chaString);

		  BufferedWriter bw = new BufferedWriter(osW);

	       //ファイルに書き込み
	      bw.write(content);
	      bw.close();
	}

	/**
	 * 2つの日付の差を求めます。
	 * 日付文字列 strDate1 - strDate2 が何日かを返します。
	 *
	 * @param strDate1    日付文字列 yyyy/MM/dd
	 * @param strDate2    日付文字列 yyyy/MM/dd
	 * @return    2つの日付の差
	 * @throws ParseException 日付フォーマットが不正な場合
	 */
	public static int differenceDays(String strDate1,String strDate2)
	    throws ParseException {
		String [] date1 = strDate1.split("/");
		String [] date2 = strDate2.split("/");

	    Date date3 = getDate(date1[0],date1[1],date1[2]);//DateFormat.getDateInstance().parse(strDate1);
	    Date date4 = getDate(date2[0],date2[1],date2[2]);//DateFormat.getDateInstance().parse(strDate2);
	    return differenceDays(date3,date4);
	}

	/**
	 * 2つの日付の差を求めます。
	 * java.util.Date 型の日付 date1 - date2 が何日かを返します。
	 *
	 * 計算方法は以下となります。
	 * 1.最初に2つの日付を long 値に変換します。
	 *  ※この long 値は 1970 年 1 月 1 日 00:00:00 GMT からの
	 *  経過ミリ秒数となります。
	 * 2.次にその差を求めます。
	 * 3.上記の計算で出た数量を 1 日の時間で割ることで
	 *  日付の差を求めることができます。
	 *  ※1 日 ( 24 時間) は、86,400,000 ミリ秒です。
	 *
	 * @param date1    日付 java.util.Date
	 * @param date2    日付 java.util.Date
	 * @return    2つの日付の差
	 */
	public static int differenceDays(Date date1,Date date2) {
	    long datetime1 = date1.getTime();
	    long datetime2 = date2.getTime();
	    long one_date_time = 1000 * 60 * 60 * 24;
	    long diffDays = (datetime1 - datetime2) / one_date_time;
	    return (int)diffDays;
	}


	public static String dateToString (Date date) {
		DateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		String tempDate = sdFormat.format(date);
		return tempDate;
	}

	public static String dateToString2 (Date date) {
		DateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd");
		String tempDate = sdFormat.format(date);
		return tempDate;
	}


	/**
	 * メール形式をチェックする。※「@」が含むかだけチェックする。
	 * ※null,""の場合はtrue。文字列がある場合のみチェックを行う。
	 * @param value
	 * @return
	 */
	public static boolean emailCheck(String value){
		if(!GenericValidator.isBlankOrNull(value) && !value.matches("^[!-~]+@[!-~]+$")){
			return false;
		}
		return true;
	}
	/**
	 * 現在時間と比較結果を戻す。
	 *	1未来
	 *	0現在
	 *	-1過去
	 * @param strDate
	 * @param format
	 * @return
	 */
	public static int strDateCompare(String strDate,String format){
		DateTool dateTool = new DateTool();
		String nowStr = dateTool.format(format,dateTool.getSystemDate());
		return strDate.compareTo(nowStr) > 0 ? 1 : ((strDate.compareTo(nowStr) == 0)? 0 :-1);
	}

	/**
	 * ダブルクォーテーション追加[タブ区切り版]、CSV、TSVに"を追加する。
	 * @param argStr
	 * @return
	 */
	public static String addDoubleStr(String argStr){
		String convert =("\""+argStr.replaceAll("\t\r\n", "\r\n")/*タブの直後改行はタグ削除*/).replace("\r\n","\r\n\""/*先頭に"*/).replace("\r\n","\"\r\n"/*最後に"*/).replace("\t", "\"\t\"");
		return convert.substring(0,convert.length()-1);
	}


	/**
	 * 半角数字チェック
	 * @param arg
	 * @return
	 */
	public static boolean isHanaku09(String arg){
		return arg != null && arg.matches(SinaburoConstant.Regex.HANKAKU_09);
	}

	/**
	 * 半角英数字チェック
	 * @param arg
	 * @return
	 */
	public static boolean isHanakuE09(String arg){
		return arg != null && arg.matches(SinaburoConstant.Regex.HANKAKU_E09);
	}

	/**
	 * 全角カナ
	 * @param arg
	 * @return
	 */
	public static boolean isZenkakuKana(String arg){
		return arg != null && arg.matches(SinaburoConstant.Regex.ZENKAKU_KANA);
	}

	/**
	 * 全角
	 * @param arg
	 * @return
	 */
	public static boolean isZenkaku(String arg){
		return arg != null && arg.matches(SinaburoConstant.Regex.ZENKAKU);
	}

	/**
	 * 電話番号
	 * @param arg
	 * @return
	 */
	public static boolean isPhoneNo(String arg){
		return arg != null && arg.replace("-", "").replace("ー", "").matches(SinaburoConstant.Regex.HANKAKU_09);
	}

	/**
	 * 郵便番号
	 * @param arg
	 * @return
	 */
	public static boolean isPostNo(String arg){
		return arg != null && arg.replace("-", "").replace("ー", "").matches(SinaburoConstant.Regex.POSTNO);
	}

	/**
	 * yyyy/MM/dd形式の次の日付を求める。
	 * @param to
	 * @return
	 */
	public static String getNextDay(String to){
		String [] yyyymmdd = to.split("/");

		return
		new DateTool().format("yyyy/MM/dd",SinaburoUtil.getAddDate(SinaburoUtil.getDate(Integer.parseInt(yyyymmdd[0]),
			Integer.parseInt(yyyymmdd[1]),Integer.parseInt(yyyymmdd[2]),0,0,0), 1) );


	}

	/**
	 * 日付の妥当性チェックを行います。
	 * 指定した日付文字列(yyyy/M/d or yyyy-M-d)が
	 * カレンダーに存在するかどうかを返します。
	 * 年は4桁である必要があり。
	 * 
	 * @param strDate チェック対象の文字列
	 * @return 存在する日付の場合true
	 */
	public static boolean checkDate(String strDate) {
	    if (strDate == null) {
	        return false;
	    }
	    try {
	    	strDate = strDate.replace('-', '/');
	    	String[] ymd = strDate.split("/");
	    	if (ymd.length != 3 || ymd[0].length() != 4) {
	    		return false;
	    	}
	    	strDate = ymd[0] + "/" + StringUtils.leftPad(ymd[1], 2, "0") + "/" + StringUtils.leftPad(ymd[2], 2, "0") ;
		    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
		    format.setLenient(false);
	        format.parse(strDate);
	        return true;
	    } catch (Exception e) {
	        return false;
	    }
	}



	/**
	 * 日付の妥当性チェック
	 * @param from 開始日 nullまたは空で判定対象外
	 * @param to   終了日 nullまたは空で判定対象外
	 * @param value 比較日
	 * @return
	 */
	public static boolean dateFromToCheck(String from, String to, String value) {
		boolean result = false;
		try {
			value = dateStrToYYMMDD(value);
			from = dateStrToYYMMDD(from);
			to = dateStrToYYMMDD(to);

			if (StringUtil.isNotBlank(from) && StringUtil.isNotBlank(to)) {
				result = value.compareTo(from) >= 0 && to.compareTo(value) >= 0;
			} else if (StringUtil.isBlank(from) && StringUtil.isNotBlank(to)) {
				result = to.compareTo(value) >= 0;
			} else if (StringUtil.isNotBlank(from) && StringUtil.isBlank(to)) {
				result = value.compareTo(from) >= 0;
			}
		} catch (Exception e) {
			return false;
		}
		return result;
	}

	
	/**
	 * YYYY/M/Dなどの日付をYYYY/MM/DDに変更する。空文字の場合そのまま返す。
	 * 
	 * @param value 日付
	 * @return YYYY/MM/DD形式の文字列
	 * @throws Exception
	 */
	public static String dateStrToYYMMDD(String value) throws Exception {
		if (StringUtil.isBlank(value)) {
			return value;
		}

		value = value.replace('-', '/');
		String[] ymd = value.split("/");
		if (ymd.length != 3 || ymd[0].length() != 4) {
			throw new Exception();
		}

		value = ymd[0] + "/" + StringUtils.leftPad(ymd[1], 2, "0") + "/" + StringUtils.leftPad(ymd[2], 2, "0");
		SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
		format.setLenient(false);
		format.parse(value);

		return value;
	}	
	
	/**
	 * 生年月日から年齢を取得する。
	 * @param strbirthDay
	 * @return
	 * @throws ParseException
	 */
	public static int getAge(String strbirthDay) throws ParseException{
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		Calendar birthDay = Calendar.getInstance();
		birthDay.setTime(sdf.parse(strbirthDay));
		Calendar today = Calendar.getInstance();
		today.setTime(sdf.parse(new SimpleDateFormat(Formats.DATATYPE_DATE_FORMAT_NON_SLASH).format(new Timestamp(System.currentTimeMillis()).getTime())));
		int age = today.get(Calendar.YEAR) - birthDay.get(Calendar.YEAR);
		birthDay.clear(Calendar.YEAR);
		today.clear(Calendar.YEAR);
		if (birthDay.after(today)) {
			age -= 1;
		}
		return age;
	}

	/**
     * 引数の文字列(UTF-8)を、Shift_JISにエンコードする。
     * 
     * @param value 変換対象の文字列
     * @return エンコードされた文字列
     */
    public static String utf8ToSjis(String value) throws UnsupportedEncodingException {
        byte[] srcStream = value.getBytes("UTF-8");
        //value = convert(new String(srcStream, "UTF-8"), "UTF-8", "SJIS");
        value = convert(new String(srcStream, "UTF-8"), "UTF-8", "Windows-31J");
        byte[] destStream = value.getBytes("Windows-31J");
        value = new String(destStream, "Windows-31J");
        return value;
    }

    /**
     * 引数の文字列を、エンコードする。
     * 
     * @param value 変換対象の文字列
     * @param src 変換前の文字コード
     * @param dest 変換後の文字コード
     * @return エンコードされた文字列
     */
    private static String convert(String value, String src, String dest) throws UnsupportedEncodingException {
        Map<String, String> conversion = createConversionMap(src, dest);
        char oldChar;
        char newChar;
        String key;
        for (Iterator<String> itr = conversion.keySet().iterator() ; itr.hasNext() ;) {
            key = itr.next();
            oldChar = toChar(key);
            newChar = toChar(conversion.get(key));
            value = value.replace(oldChar, newChar);
        }
        return value;
    }
    
    /**
     * エンコード情報を作成する
     * 
     * @param src 変換前の文字コード
     * @param dest 変換後の文字コード
     * @return エンコードされた文字列
     */
    private static Map<String, String> createConversionMap(String src, String dest) throws UnsupportedEncodingException {
        Map<String, String> conversion = new HashMap<String, String>();
        if ((src.equals("UTF-8")) && (dest.equals("SJIS"))) {
            // -(全角マイナス)
            conversion.put("U+FF0D", "U+2212");
            // ~(全角チルダ)
            conversion.put("U+FF5E", "U+301C");
            // ¢(セント)
            conversion.put("U+FFE0", "U+00A2");
            // £(ポンド)
            conversion.put("U+FFE1", "U+00A3");
            // ¬(ノット)
            conversion.put("U+FFE2", "U+00AC");
            // ―(全角マイナスより少し幅のある文字)
            conversion.put("U+2015", "U+2014");
            // ∥(半角パイプが2つ並んだような文字)
            conversion.put("U+2225", "U+2016");

        } else if ((src.equals("SJIS")) && (dest.equals("UTF-8"))) {
            // -(全角マイナス)
            conversion.put("U+2212", "U+FF0D");
            // ~(全角チルダ)
            conversion.put("U+301C", "U+FF5E");
            // ¢(セント)
            conversion.put("U+00A2", "U+FFE0");
            // £(ポンド)
            conversion.put("U+00A3", "U+FFE1");
            // ¬(ノット)
            conversion.put("U+00AC", "U+FFE2");
            // ―(全角マイナスより少し幅のある文字)
            conversion.put("U+2014", "U+2015");
            // ∥(半角パイプが2つ並んだような文字)
            conversion.put("U+2016", "U+2225");

        } else {
            throw new UnsupportedEncodingException("この文字コードはサポートしていません。\n・src=" + src + ",dest=" + dest);
        }
        return conversion;
    }

    /**
     * 16進表記の文字を取得する。
     * 
     * @param value 変換対象の文字列
     * @return 16進表記の文字
     */
    private static char toChar(String value) {
        return (char)Integer.parseInt(value.trim().substring("U+".length()), 16);
    }

	public static boolean isAllowedSrc(String ipAddress, List<String> allowedList) {
		if (!allowedList.isEmpty()) {
			for (String address : allowedList) {
				if (address.endsWith("*") && ipAddress.startsWith(address.substring(0, address.length() - 1))) {
					return true;
				} else if (address.contains("/")) {
					try {
						SubnetUtils subnetUtils = new SubnetUtils(address);
						subnetUtils.setInclusiveHostCount(true);
						if (subnetUtils.getInfo().isInRange(ipAddress)) {
							return true;
						}
					} catch (Exception e) {
						LOGGER.fatal("invalid address " + address + " : " + e.toString());
					}
				} else if (address.equals(ipAddress)) {
					return true;
				}
			}
		} else {
			// 未設定の場合は、IP制限なし
			return true;
		}
		return false;
	}
	
	
	/**
	 * UTF8からSJISに変換時文字化ける文字を置換
	 * 
	 * @param s
	 * @return
	 */
	public static String toSJIS(String s) {
		
		if(s == null){
			return "";
		}
		
		StringBuffer sb = new StringBuffer();
		char c;

		for (int i = 0; i < s.length(); i++) {
			c  = s.charAt(i);
			switch (c) {
				case 0x301c:
					c = 0xff5e;
					break;
				case 0x2016:
					c = 0x2225;
					break;
				case 0x2212:
					c = 0xff0d;
					break;
				case 0x00a2:
					c = 0xffe0;
					break;
				case 0x00a3:
					c = 0xffe1;
					break;
				case 0x00ac:
					c = 0xffe2;
					break;
				case 0x2014:
					c = 0x2015;
					break;
				default:
					break;
			}

			sb.append(c);
		}
		return new String(sb);
	}
	
}