Package ch.k43.util


package ch.k43.util
Java Utility Package (Freeware)

A high-performance, user-friendly programming toolkit designed for Java back-end developers.

This package holds all classes used by the Java Utility Package. The full documentation with examples can be found on java-util.k43.ch

 JDBC Example
 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.prepare("INSERT INTO addresses (lastname, firstname) VALUES (?, ?)");
    db.execPrepare("Smith", "Joe");
    db.execPrepare("Miller", "Bob");
    db.execPrepare("Johnson", "Evelyn");
    db.exec("SELECT * FROM addresses");
    System.out.println(db.getDataAsJSON());
 }
 
 HTTPS Example
 KHTTPClient http = new KHTTPClient();
 
 if (!http.get("https://reqbin.com/echo/get/json")) {
    KLog.error("Error: {}", http.getLastError());
 } else {
    System.out.println(http.getResponseDataAsString());
 }
 
 SMTP Example
 KSMTPMailer mailer = new KSMTPMailer();

 mailer.setFrom("john.doe@acme.com");
 mailer.setTo("bob.smith@hotmail.com");
 mailer.setSubject("Subject");
 mailer.addText("Here is your requested file");
 mailer.addFile("test.txt");
 mailer.addText("Regards, John");
 mailer.send();
 
Author:
andy.brunner@k43.ch
  • Classes
    Class
    Description
    Static class with many utility methods.
    Class to support all JDBC compliant databases with basic database functions.
    Static class with a collection of file utility methods.
    Hello World example.
    Support basic HTTP/HTTPS client transactions.
    Static class for simple logging.
    Format logging output as single CSV line with UUID, time stamp, logging level, code location and the logging information.
    Java logging handler to output logging data to any compliant JDBC database.
    Format logging output as JSON formatted string with UUID, time stamp, logging level, code location and the logging information.
    Format logging output as single formatted line with time stamp, logging level, code location and the logging information.
    Java logging handler to send logging data to an SMTP host.
    This thread is started by the SMTP logging handler to send the SMTP mail.
    Format logging output as XML formatted string with UUID, time stamp, logging level, code location and the logging information.
    Format logging output as YAML formatted string with UUID, time stamp, logging level, code location and the logging information.
    Compose and send MIME multipart email to an SMTP host.
    Supported TCP socket connections to non-TLS, TLS and TLS with client authentication.
    This class provides support for a TLS-secured or non-secured socket server.
    Class to handle user connections accepted by KSocketServerListener.
    Simple upper case echo server to show a sample KSocketServerThread implementation.
    This class adds some convenient methods for starting and stopping Java threads.
    Simple timer class.