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
HBase Client 2.5.5 in JDK 11
Because of the vulnerability scan results of the project, the JDK version must be upgraded from 8 to 11 to complete the repair. The original HBase Client version 1.2 we used was incompatible with JDK 11, so we had to … Continue reading
[Java] Create CSV files with BOM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
public static final String UTF8_BOM = "\uFEFF"; public ByteArrayInputStream createFile(Object object) { try { CSV csv = (CSV) object; StringBuffer sb = new StringBuffer(); sb.append(UTF8_BOM); if (csv.getHeaderList() != null) { sb.append(StringUtils.join(csv.getHeaderList().toArray(new String[0]), ",")).append("\n"); } for (List<String> row : csv.getDataList()) { sb.append(StringUtils.join(row.toArray(new String[0]), ",")).append("\n"); } return new ByteArrayInputStream(sb.toString().getBytes("UTF-8")); } catch (Exception e) { return null; } } |
Posted in Java
Comments Off on [Java] Create CSV files with BOM
[Java] Google authenticator
Reference: 1. Greddy’s Blogs: Google Authenticator實作 2. 菜鳥工程師 肉豬: Spring Boot 使用Google身分驗證器做TOTP驗證 Google Authenticator TOTP auth
[Java] Download file without saving
Source: CSDN: InputStream类available和read方法可能读取不到完整的流数据 stackoverflow: How to read a http file inmemory without saving on local drive?
1 2 3 4 5 6 7 8 9 10 11 |
private static InputStream download(String sourceURL) throws Exception { InputStream inputStream = new URL(sourceURL).openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int n = 0; while (-1 != (n = inputStream.read(buffer))) { output.write(buffer, 0, n); } return new ByteArrayInputStream(output.toByteArray()); } |
Posted in Java
Comments Off on [Java] Download file without saving
[Java] String with number format
Reference
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 |
public static void main(String[] args) throws Exception { String number = "1000500000"; double amount = Double.parseDouble(number); DecimalFormat intFormatter = new DecimalFormat("#,###"); DecimalFormat floatFormatter = new DecimalFormat("#,###.00"); System.out.println("==int=="); System.out.println(intFormatter.format(amount)); System.out.println(String.format("%,d", Integer.parseInt((number)))); System.out.println(number.replaceAll("(\\d)(?=(\\d{3})+$)", "$1,")); System.out.println("==float=="); System.out.println(floatFormatter.format(amount)); System.out.println(String.format("%,.2f", Float.parseFloat((number)))); } ==int== 1,000,500,000 1,000,500,000 1,000,500,000 ==float== 1,000,500,000.00 1,000,499,968.00 |
Posted in Java
Comments Off on [Java] String with number format
[Java] Mask some part of String
Reference: [stackoverflow] Mask some part of String
1 2 3 |
return String.replaceAll("\\b(\\d{3})\\d+(\\d{3})", "$1****$2"); # 1234567890 => 123****890 |
Posted in Java
Comments Off on [Java] Mask some part of String
[Java] Append string with adaptive font size to image
Ref: https://blog.csdn.net/zengrenyuan/article/details/80281738
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 |
public static ByteArrayOutputStream encodeWithWaterMark(String content) { if (FRONT_IMAGE == null) { return encode(content); } ByteArrayOutputStream os = null; try { BitMatrix matrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, WIDTH, HEIGHT); BufferedImage backImage = QRCodeUtils.toBufferedImage(matrix); int fontSize = 20; String stringContent = "邀請QRCode (一般)"; Font font = new Font("Noto Sans TC", Font.PLAIN, fontSize); FontDesignMetrics metrics = FontDesignMetrics.getMetrics(font); int width = getWordWidth(font, stringContent); while (width > WIDTH) { //if string width > image width ➔ use smaller font fontSize = fontSize - 1; font = new Font("Noto Sans TC", Font.PLAIN, fontSize); metrics = FontDesignMetrics.getMetrics(font); width = getWordWidth(font, stringContent); } Graphics2D g = backImage.createGraphics(); g.setFont(font); g.setColor(Color.BLACK); //text-align:center & bottom g.drawString(stringContent, (WIDTH - width) / 2, HEIGHT - metrics.getAscent()); g.dispose(); os = new ByteArrayOutputStream(); if (!ImageIO.write(backImage, IMAGE_FORMAT, os)) { throw new IOException("Could not write an image of format png"); } } catch (Exception e) { LOG.error(Constants.EXCEPTION_PREFIX, e); } return os; } private static BufferedImage toBufferedImage(BitMatrix matrix) { int width = matrix.getWidth(); int height = matrix.getHeight(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE); } } return image; } public static int getWordWidth(Font font, String content) { FontDesignMetrics metrics = FontDesignMetrics.getMetrics(font); int width = 0; for (int i = 0; i < content.length(); i++) { width += metrics.charWidth(content.charAt(i)); } return width; } |
Posted in Java
Comments Off on [Java] Append string with adaptive font size to image
[HBase] security issue
error message: com.a.b.c.exception.BaseDAOException: org.apache.hadoop.hbase.security.AccessDeniedException: org.apache.hadoop.hbase.security.AccessDeniedException: Insufficient permissions for user ‘Cowman’ (table=ABC, action=READ) in jvm conf. add “-DHADOOP_USER_NAME=webuser”
Posted in HBase, Java
Leave a comment
[HBase] convert long value to bytes
Java code:
1 2 3 4 5 6 |
public static void main(String[] args) { String stringValue = Bytes.toStringBinary(Bytes.toBytes(1532080782183l)); System.out.println(stringValue); Long longValue = Bytes.toLong(Bytes.toBytesBinary(stringValue)); System.out.println(longValue); } |
HBase shell command:
1 2 3 4 |
hbase(main):056:0> Bytes.toStringBinary(Bytes.to_bytes(1532080782183)) => "\\x00\\x00\\x01d\\xB7!{g" hbase(main):057:0> Bytes.toLong("\x00\x00\x01d\xB7!{g".to_java_bytes) => 1532080782183 |
Posted in HBase, Java
Leave a comment
[Java] Convert Hex to String
1 2 3 4 5 6 7 8 9 10 11 12 |
<code> public static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i &lt; len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) &lt;&lt; 4) + Character.digit(s.charAt(i+1), 16)); } return data; } </code> |
stackoverflow: Convert a string representation of a hex dump to a byte array using Java?
Posted in Java
Leave a comment