面向 Java 后端开发人员的快速且易于使用的编程工具包
在我作为管理员和开发人员的职业生涯中,我多次从无数的免费软件和开源产品中受益。因此,我很自然地也为这个社区做出贡献。
这个 Java 类集合是在各种项目过程中创建的,并将进一步开发。我希望这个工具也能为您服务。
https://java-util.k43.ch
设计目标
public static void main(String[] args) { KLog.info("Start"); int result = 0; try { result = 10 / 0; } catch (Exception e) { KLog.error(e); } KLog.debug("Result is " result); }
2024-09-16T07:17:11.095 D main[1]:ch.k43.util.KLog:open:459 ===== Application started 2024-09-16T07:17:11.048 ===== 2024-09-16T07:17:11.111 D main[1]:ch.k43.util.KLog:open:460 Java Utility Package (Freeware) ch.k43.util Version 2024.09.15 2024-09-16T07:17:11.112 D main[1]:ch.k43.util.KLog:open:463 Homepage java-util.k43.ch - Please send any feedback to [email protected] 2024-09-16T07:17:11.122 D main[1]:ch.k43.util.KLog:open:466 Host ab-macbook-pro (10.0.0.105) 2024-09-16T07:17:11.122 D main[1]:ch.k43.util.KLog:open:467 OS platform Mac OS X (Version 14.6.1/aarch64) 2024-09-16T07:17:11.123 D main[1]:ch.k43.util.KLog:open:471 OS disk space total 3.63 TB, free 2.37 TB, usable 2.37 TB 2024-09-16T07:17:11.123 D main[1]:ch.k43.util.KLog:open:474 Java version 21 (OpenJDK 64-Bit Server VM - Eclipse Adoptium) 2024-09-16T07:17:11.123 D main[1]:ch.k43.util.KLog:open:477 Java CPUs 10 2024-09-16T07:17:11.124 D main[1]:ch.k43.util.KLog:open:481 Java heap maximum 16.00 GB, current 1.00 GB, used 7.68 MB, free 1016.32 MB 2024-09-16T07:17:11.124 D main[1]:ch.k43.util.KLog:open:485 Java locale de/CH, time UTC 02:00 2024-09-16T07:17:11.125 D main[1]:ch.k43.util.KLog:open:488 Java classpath ../bin/:../lib/angus-mail-2.0.3.jar:../lib/jakarta.mail-api-2.1.3.jar:../lib/org.json.20230618.jar:../lib/h2-2.2.224.jar:../lib/jakarta.activation-api-2.1.3.jar:../lib/angus-activation-2.0.2.jar 2024-09-16T07:17:11.125 I main[1]:Test:main:9 Start 2024-09-16T07:17:11.125 E main[1]:Test:main:16 ===> java.lang.ArithmeticException: / by zero 2024-09-16T07:17:11.126 E main[1]:Test:main:16 ===> Stack[1]: Test.main(Test.java:14) 2024-09-16T07:17:11.126 D main[1]:Test:main:19 Result is 0
try (KDB db = new KDB(KDB.JDBC_H2, "jdbc:h2:mem:mydb", "", "")) { KLog.abort(!db.isConnected(), "Error: " db.getErrorMessage()); db.exec("CREATE TABLE ADDRESSES (SEQUENCE INT AUTO_INCREMENT, LASTNAME VARCHAR(20), FIRSTNAME VARCHAR(20))"); db.exec("INSERT INTO ADDRESSES (LASTNAME, FIRSTNAME) VALUES ('Smith', 'John')"); db.exec("INSERT INTO ADDRESSES (LASTNAME, FIRSTNAME) VALUES ('Miller', 'Bob')"); db.exec("INSERT INTO ADDRESSES (LASTNAME, FIRSTNAME) VALUES ('Johnson', 'Eve')"); db.exec("SELECT * FROM ADDRESSES", 10); System.out.println(db.getDataAsTable()); System.out.println(db.getDataAsJSON()); }
SEQUENCE LASTNAME FIRSTNAME 1 Smith John 2 Miller Bob 3 Johnson Eve
{ "ADDRESSES": [ { "SEQUENCE": 1, "LASTNAME": "Smith", "FIRSTNAME": "John" }, { "SEQUENCE": 2, "LASTNAME": "Miller", "FIRSTNAME": "Bob" }, { "SEQUENCE": 3, "LASTNAME": "Johnson", "FIRSTNAME": "Eve" } ] }
KSMTPMailer mailer = new KSMTPMailer(); mailer.setFrom("[email protected]"); mailer.setTo("[email protected]"); mailer.setSubject("Subject"); mailer.addHTML("Your requested files
"); mailer.addText("Body Text"); mailer.addFile("test1.txt"); mailer.addFile("test2.txt"); mailer.addText("Regards, John"); mailer.send();
Properties props = new Properties(); props.put("Authorization", "Basic " K.encodeBase64(userName ':' password); KHTTPClient http = new KHTTPClient(); if (!http.post("https://example.com:4443", props, "HTTP body data")) { KLog.abort("HTTP POST failed - " http.getLastError()); }
// Wait 1/4 second K.waitMilliseconds(250); // Get DNS MX record(s) String[] mxRRs = K.queryDNS("MX", "yahoo.com"); // // AES-256 Encryption/Decryption // String secretKey = "This is the secret key"; // Create a simple text file KFile.writeFile("This is a simple text file", "AES-Text.txt"); // Generate and save random AES-256 initialization vector KFile.writeFile(K.getRandomBytes(16), "AES.iv"); // Encrypt byte[] clearText = KFile.readByteFile("AES-Text.txt"); byte[] initVector = KFile.readByteFile("AES.iv"); byte[] cipherText = K.encryptAES256(clearText, secretKey.getBytes(), initVector); KFile.writeFile(cipherText, "AES-Text.encrypted"); // Decrypt cipherText = KFile.readByteFile("AES-Text.encrypted"); initVector = KFile.readByteFile("AES.iv"); clearText = K.decryptAES256(cipherText, secretKey.getBytes(), initVector);
玩得开心,让我知道您喜欢什么以及需要改进什么。您可以通过电子邮件 [[email protected]] 或 Mastodon 联系我。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3