Category Archives: 程式語言

[Java, HBase] Hostname is very important!

If the connection is failed, try to check the hdfs uri setting, it might be used hostname.

Posted in HBase, Java | Leave a comment

[Java] Connect LDAP (subdomain).

Ref. referrals & global catalog, AD Child Domain Referral Searches by Rajnish Bhatia If you want to search all subdomain, the port of ‘PROVIDER_URL’ might be use in 3268.

Posted in Java | 1 Comment

[Java] Check apache poi version

Ref: The Apache POI project – Frequently Asked Questions: My code uses some new feature, compiles fine but fails when live with a “MethodNotFoundException” or “IncompatibleClassChangeError” ClassLoader classloader = org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader(); URL res = classloader.getResource(“org/apache/poi/poifs/filesystem/POIFSFileSystem.class”); String path = res.getPath(); System.out.println(“Core POI … Continue reading

Posted in Java | Leave a comment

[Java] Write xls files

public String createFile(Object object) { try { Excel excel = (Excel) object; HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); for (SheetContent sheetContent:excel.getSheets()) { HSSFSheet sheet = hssfWorkbook.createSheet(sheetContent.getName()); List<HSSFCellStyle> formats = new ArrayList<>(); /** format */ for (String format:sheetContent.getFormats()) { HSSFCellStyle cs = … Continue reading

Posted in Excel, Java | Leave a comment

[Java] Binary numbers in enum type.

public enum Type { /** none */ NONE(0), /** ONE */ ONE(1), /** TWO */ TWO(2), /** FOUR */ FOUR(4), /** EIGHT */ EIGHT(8), /** SIXTEEN */ SIXTEEN(16); private int key; private static int[] binaryArray = { 0, 1, 2, … Continue reading

Posted in Java | Leave a comment

[Java] String.format

private String GroupMessageAuto = “已完成自動同步動作,共計新增 %s 筆、刪除 %s 筆、同步 %s 筆”; groupMsg = String.format(GroupMessageAuto, syncCount.getAdd(), syncCount.getDel(), syncCount.getSync());

Posted in Java | Leave a comment

[Java、HBase] Retrieving timestamp form HBase row

Ref. stackoverflow: retrieving timestamp from hbase row HTableInterface hTableInterface = CONNECTION.getTable(Table.SCHEMA_NAME); Result result = hTableInterface.get(get); Date date = new Date(result.raw()[0].getTimestamp()); System.out.println(“DateTime: ” + sdf.format(date)); we must edit HBaseSettings to set hbaseConf.set(HBASE_ENV_KEY_ZOOKEEPER_QUORUM, “target_zookeeper_address”);

Posted in HBase, Java | Tagged , | Leave a comment

[Java] Transform currentTimeMillis to readable date format

Ref. stackoverflow: how-to-transform-currenttimemillis-to-a-readable-date-format SimpleDateFormat sdf = new SimpleDateFormat(“MMM dd,yyyy HH:mm”); Date date = new Date(System.currentTimeMillis()); System.out.println(“DateTime: ” + sdf.format(date));

Posted in Java | Tagged | Leave a comment

[Java] Check UUID format

Ref. BUKKIT: Best way to check if a String is a UUID private static boolean checkUUIDFromat(String uuid) { if (uuid.matches(“[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}”)) { return true; } return false; }

Posted in Java | Leave a comment

[Java] Check string is a messy code?

Ref: Java判断字符串是否是乱码(亲测可用) public static boolean isChinese(char c) { Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) { return true; } … Continue reading

Posted in Java | Leave a comment