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

Posted in HBase, Java | Comments Off on HBase Client 2.5.5 in JDK 11

[Java] Create CSV files with BOM

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()) { … Continue reading

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

Posted in Auth, Java | Comments Off on [Java] Google authenticator

[Java] Download file without saving

Source: CSDN: InputStream类available和read方法可能读取不到完整的流数据 stackoverflow: How to read a http file inmemory without saving on local drive? private static InputStream download(String sourceURL) throws Exception { InputStream inputStream = new URL(sourceURL).openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int … Continue reading

Posted in Java | Comments Off on [Java] Download file without saving

[Java] String with number format

Reference 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 … Continue reading

Posted in Java | Comments Off on [Java] String with number format

[Java] Mask some part of String

Reference: [stackoverflow] Mask some part of String 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 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 … Continue reading

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: 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: 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

<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) + … Continue reading

Posted in Java | Leave a comment