Categories
- FFMpeg (5)
- Libav (1)
- Google (3)
- iBeacon (1)
- LDAP (3)
- Me (2)
- Network (11)
- OS (149)
- RTMP (4)
- SIP (1)
- Kamailio (1)
- SNMP (1)
- VMware (20)
- VCP考試 (1)
- 伺服器 網站服務 (105)
- 名詞解釋 (4)
- 專案管理 (1)
- 工具軟體 (50)
- Adobe (1)
- FMS (1)
- Cloudera (1)
- Docker (1)
- Eclipse (4)
- Intellij (2)
- OBS (2)
- Office (10)
- Excel (4)
- PowerPoint (5)
- Postman (1)
- Splunk (13)
- Virtualbox (2)
- Visual Studio (2)
- 文字編輯器 (10)
- Sublime Text 2 (6)
- Sublime Text 3 (3)
- Vim (3)
- 連線工具 (1)
- Xshell (1)
- Adobe (1)
- 程式語言 (79)
- CSS (2)
- HTML (2)
- iOS (1)
- Java (30)
- JavaScript (5)
- jQuery (4)
- jsTree (2)
- JSP (3)
- PHP (16)
- Python (7)
- Ruby (1)
- sed (1)
- Shell Script (8)
- Windows Bash Script (1)
- XML (1)
- 資料庫 (37)
- FFMpeg (5)
Category Archives: Java
[Jersey] disable decode the URL path
use annotation “@Encoded” Ex:
1 2 |
@Path("{first}/get") public Response getYouWant(@Context HttpHeaders httpHeaders, @PathParam("first") String first, @QueryParam("second") @Encoded String second); |
Posted in Java
Leave a comment
open external program from java for mac os x
1 2 |
String[] cmds = {"open", tempFile.getAbsolutePath(), "-a", "/Applications/Microsoft Office 2011/Microsoft Excel.app"}; Runtime.getRuntime().exec(cmds); |
Posted in Java, Mac, Office
Leave a comment
Gson usage : formJson
avoid to face the exception ‘java.lang.ClassCastException With com.google.gson.internal.LinkedTreeMap cannot be cast to…’, we use the TypeToken to convert json to List
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 |
public class Object { @SerializedName("n") private String name; @SerializedName("i") private String id; public String getName() { return name; } public Object setName(String name) { this.name = name; return this; } public String getId() { return id; } public Object setId(String id) { this.id = id; return this; } } // [{"n":"cowman","i":"cowman@xxx.com.tw"}, {"n":"cowman1","i":"cowman1@xxx.com.tw"}] List<Object> ObjectList = new Gson().fromJson(targets, new TypeToken<List<Object>>(){}.getType()); |
Posted in Java
Leave a comment
[Java] unicode to string
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public static void main(String[] args) { try { String abc = "0043006F0077006D0061002E002E002E90808ACB"; System.out.print(getString(abc)); } catch (Exception e) { System.out.println("err"); } } public static String getString(String strValue) { StringBuilder str = new StringBuilder(); String temp; for (int i = 0; i < strValue.length(); i = i + 4) { temp = strValue.substring(i, i + 4); str.append((char) Integer.parseInt( temp, 16 )); } return str.toString(); } |
Posted in Java
Leave a comment
[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.
[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”
1 2 3 4 5 |
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 came from " + path); |
Posted in Java
Leave a comment
[Java] Write xls files
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 |
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 = hssfWorkbook.createCellStyle(); HSSFDataFormat df = hssfWorkbook.createDataFormat(); cs.setDataFormat(df.getFormat(format)); formats.add(cs); } /** header */ HSSFRow headerRow = sheet.createRow(0); for (int i = 0; i < sheetContent.getHeaders().size(); i++) { HSSFCell cell = headerRow.createCell(i); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(sheetContent.getHeaders().get(i)); } /** content */ for (int i = 0; i < sheetContent.getRows().size(); i ++) { HSSFRow dataRow = sheet.createRow(i + 1); for (int j = 0; j < sheetContent.getRows().get(i).getCells().size(); j++) { HSSFCell cell = dataRow.createCell(j); if (StringUtils.isNotEmpty(sheetContent.getFormats().get(j))) { cell.setCellValue(Double.parseDouble(sheetContent.getRows().get(i).getCells().get(j))); cell.setCellStyle(formats.get(j)); } else { cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(sheetContent.getRows().get(i).getCells().get(j)); } } } /** auto size */ for (int i = 0; i < sheet.getRow(0).getPhysicalNumberOfCells(); i++) { sheet.autoSizeColumn(i); } } FileOutputStream out = new FileOutputStream(new File("Excel.xls")); hssfWorkbook.write(out); out.close(); return "ok"; } catch (Exception e) { LOG.error(Constants.EXCEPTION_PREFIX, e); return null; } } public class Excel { List<SheetContent> sheets; public List<SheetContent> getSheets() { return sheets; } public Excel setSheets(List<SheetContent> sheets) { this.sheets = sheets; return this; } public Excel addSheets(SheetContent sheet) { if (this.sheets == null) { this.sheets = new ArrayList<>(); } this.sheets.add(sheet); return this; } } public class SheetContent { private String name; private List<String> formats; private List<String> headers; private List<Row> rows; public String getName() { return name; } public SheetContent setName(String name) { this.name = name; return this; } public List<String> getFormats() { return formats; } public SheetContent setFormats(List<String> formats) { this.formats = formats; return this; } public List<String> getHeaders() { return headers; } public SheetContent setHeaders(List<String> headers) { this.headers = headers; return this; } public List<Row> getRows() { return rows; } public SheetContent setRows(List<Row> rows) { this.rows = rows; return this; } } public class Row { private List<String> cells; public List<String> getCells() { return cells; } public Row setCells(List<String> cells) { this.cells = cells; return this; } } |
Posted in Excel, Java
Leave a comment
[Java] Binary numbers in enum type.
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 |
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, 4, 8, 16 }; Type(int code) { this.key = code; } public int getKey() { return key; } public static void main(String[] args) { System.out.println(findListByKey(60)); } public static List<Type> findListByKey(int key) { List<Type> matchList = new ArrayList<>(); List<Integer> binarySequence = getBinarySequence(key); for (Integer code:binarySequence) { matchList.add(findByKey(code)); } return matchList; } public static Type findByKey(int key) { Type match; for (Type e : values()) { if (e.getKey() == key) { match = e; return match; } } return NONE; } private static List<Integer> getBinaryNumberSequence(int target){ List<Integer> result = new ArrayList<>(); boolean flag = true; while (flag == true) { int code = findCloseDigit(target); target = target - code; result.add(code); if (target == 0) { flag = false; } } return result; } private static int findCloseDigit(int target) { int result = 0; for (int code:binaryArray) { if (code <= target) { result = code; } else { break; } } return result; } } |
Posted in Java
Leave a comment
[Java] String.format
1 2 3 |
private String GroupMessageAuto = "已完成自動同步動作,共計新增 %s 筆、刪除 %s 筆、同步 %s 筆”; groupMsg = String.format(GroupMessageAuto, syncCount.getAdd(), syncCount.getDel(), syncCount.getSync()); |
Posted in Java
Leave a comment