common

ICL : Intellisrc Common Library : This library can help you to write less code and speedup the development of your next great application. It is particularly designed to accomplish most of the common tasks required by backend services.

GPL-3.0 License

Stars
1

ICL Library

This library can help you to write less code and speedup the development of your next great application. It is particularly designed to accomplish most of the common tasks required by backend services.

Goal

Provide the best implementation or wrap the best libraries to make it easier to accomplish most common development tasks (like web applications, database connections, security, etc).

What is in it?

With this library you can:

  • Simplify your code by using GroovyExtend library (already included)
  • Use configuration files easily, log and rotate logs, start your application in a more elegant way and more (core module and log module)
  • Set up back-end web services (HTTP or WebSockets, using Spark-Java Web Framework) (web module)
  • Create specialized threads, analyze them and manage them easily (thread module)
  • Manage databases using only Java objects or interact with them using a simple fluid SQL query builder (using JDBC) (db module)
  • Send emails with attachments through SMTP, create FTP, UDP or TCP servers and clients (net module)
  • Encrypt data or hash passwords easily and safely (using BountyCastle library) (crypt module)
  • Create a terminal application in which you can interact using commands (using JLine) (term module)
  • Communicate through a serial port (JSSC wrapper) (serial module)
  • Use cache, monitor your hardware or automate configuration changes (using Jedis or BerkeleyDB) (etc module)

NOTE : This library was designed using Groovy, but it can be used in Java and Kotlin (however, all the examples in the documentation are in Groovy).

Usage

How to use it in your project:

Maven:

<dependency>
  <groupId>com.intellisrc</groupId>
  <artifactId>MODULE</artifactId>
  <version>VERSION</version>
</dependency>

Gradle:

dependencies {
    implementation 'com.intellisrc:MODULE:VERSION'
    // or extended annotation:
    implementation group: 'com.intellisrc', name: 'MODULE', version: 'VERSION'
}

Follow the instructions on the last published version for each module in maven repository

In which VERSION is for example: 2.8.x, and MODULE any of these:

You can find some examples for each module here: https://gitlab.com/intellisrc/common_examples/

Modules

For more detailed explanation, click on the module title.

Notes:

  • classes marked with are the most commonly used classes for that module.
  • classes marked with @, are unlikely to be used directly, but may be of your interest.

core

Basic functionality that is usually needed in any project. For example, configuration, logging, executing commands, controlling services and displaying colors in the console. read more...

Class Usage
AnsiColor Color dictionary for Linux terminal
Cmd Execute system commands
Config Manage configuration files (by default config.properties)
Log Log messages to SLF4J
Millis Milliseconds constants to be used instead numeric values.
Secs Seconds constants to be used instead numeric values.
SysClock Provides simple methods to interact with LocalDateTime. Useful for Unit Testing.
SysInfo Get information about the system
SysMain Convert class into runnable class
SysService Convert class into service (only one by project)
@ StringProperties Base class for properties setters and getters
Version Return system/application version and makes it easy to handle versions

Documentation / JavaDoc

log

Includes : core

SLF4J colorful logger with many options and easy to use. You can add customized loggers and personalize the way your logs look. Generally you will use this module through core.Log class. read more...

Class Usage
@ CommonLogger Main logger which will handle multiple printers
@ BaseLogger Provides basic settings for printers
@ PrintLogger Prints to stdout (supports cache)
@ PrintStdErrLogger Prints to stderr (supports cache)
@ FileLogger Prints to a file
@ CommonLoggerFactory Used by SLF4J to get CommonLogger instance
@ CommonLoggerService Service provider for SLF4J

Documentation / JavaDoc

etc

Includes : core

Extra functionality which is usually very useful in any project. For example, monitoring Hardware, compressing or decompressing data, store data in memory cache, manage system configuration in a multithreading safe environment (using Redis or BerkeyleyDB), simple operations with bytes, etc. read more...

Class Usage
AutoConfig A set of classes to automate changes in configuration with documentation, backed up on disk (multithreading safe)
BerkeleyDB Key - Value No-SQL database which requires almost no configuration (wrapper)
Bytes Common operations with byte[]
Cache Keep objects in memory to speed-up applications
CacheObj Generic implementation of Cache
Calc Provide common math calculations
Hardware Get information about OS
JSON Convert from and to JSON format (Using Groovy JSON)
@ JarResource Store resources in JAR
@ Metric Keep track of changes in values (used by Hardware)
Mime Get Mime types from files or streams
Pack Methods to convert byte[] to int, long and back again
Redis A wrapper around Jedis to make it even easier
YAML Convert from and to YAML format
Zip Compress files

Documentation / JavaDoc

db

Includes : core, etc

Manage SQL databases, such as MySQL, SQLite, Postgresql. (for no-sql databases, see etc module) Create, store and perform CRUD operations to data without having to use SQL (a light-weight implementation as an alternative to Hibernate). read more...

NOTE : You may need to include your database driver as dependency in order to use this module.

Class Usage
Database Main class which will handle connections to SQL databases
DB Object to interact with the databases (Fluid SQL query builder)
Query Handles SQL queries
Table, Model Automatic table creation/update and CRUD data manipulations
@TableMeta, @ModelMeta Additional options to the above classes
@ Data Object returned by SQL databases and which can be converted into different classes
@ DBPool Keep connections in a pool to increase performance
@ Dummy Dummy database (used for unit testing)
@ DummyConnector Simulate and log DB connections (used for unite testing)
@ JDBCConnector A single JDBC connection
@ PoolConnector Implements a connector to be used in DBPool
@ JDBC Extend this class to create your own JDBC connection
Derby JDBC implementation for Derby databases
Firebird JDBC implementation for Firebird databases
MySQL JDBC implementation for MySQL databases
MariaDB JDBC implementation for MariaDB databases
Oracle JDBC implementation for Oracle databases
PostgreSQL JDBC implementation for PostgresSQL databases
SQLite JDBC implementation for SQLite databases
SQLServer JDBC implementation for SQL Server databases

Documentation / JavaDoc

net

Includes : core, etc, crypt

Classes related to networking. For example, sending emails through SMTP, connecting or creating TCP/UDP servers, getting network interfaces and perform netmask calculations, etc. read more...

Class Usage
Email Verify email format
MacAddress Convert format from and to MacAddress XX:XX:XX:XX
Network Methods related to networking and ip addresses but not to NetworkInterface
NetFace Simple representation of a Network Interface
Smtp Class to send emails using SMTP server
FtpClient FTP client
TCPClient TCP client
TCPServer TCP server
UDPClient UDP client
UDPServer UDP server

Documentation / JavaDoc

serial

Includes : core, etc

Manage serial communication easily. It uses the JSSC library in the background. read more...

Class Usage
@ Seriable Interface for common ports
Serial Use a serial port (connect, read, write, disconnect)
SerialDummy Dummy implementation of Seriable for Unit Testing
@ SerialReader Class to only read data from a Serial port

Documentation / JavaDoc

web

Includes : core, etc, net

Create restful HTTP (GET, POST, PUT, DELETE, etc) or WebSocket application services. Manage JSON data from and to the server easily. It is build on top of Spark-Java Web Framework, so it is very flexible and powerful, but designed to be elegant and easier to use. read more...

Class Usage
Service Defines a single service to be used in WebService
ServiceOutput Customize output response from a Service
@ Serviciable Generic interface for services
ServiciableAuth Interface to be used in services which requires sessions
ServiciableHTTPS Interface to be used to support SSL
ServiciableSingle Defines a web service with a single Service
ServiciableMultiple Defines a web service with multiple Service
ServiciableWebSocket Defines a web service using websockets
@ Session Represents a user session
UploadFile Represents an uploaded file
WebService Main class used to create a web server. It wraps Spark
WebSocketService Wrapper class to use with websockets
WebSocketServiceClient Client for websocket services
services/LoginService Implementation for login services
services/LogService Implementation to browse logs in a browser

Documentation / JavaDoc

crypt

Includes : core, etc

Offers methods to encode, decode, hash and encrypt information. It is built using the amazing BouncyCastle library by simplifying its usage without reducing its safety. read more...

Class Usage
Crypt Base class for all other classes in this module. It provides random generators and byte[] related methods
AES Two way encryption (fixed key length required)
PGP Two way encryption using OpenPGP (doesn't require fixed key length)
Hash Provides many simple hash algorithms like MD5, SHA .. SHA512, and others available through BountyCastle (like: TIGER, WHIRLPOOL, etc.)
@ Hashable Interface for Hash and PasswordHash
PasswordHash Provides strong hashing algorithms for passwords, like: BCRYPT, SCRYPT and PBKDF2
LpCode Provides String obfuscation, reduction or conversion using UTF-8 character planes

Documentation / JavaDoc

thread

Includes : core

Manage Tasks (Threads) with priority and watch its performance. You can create parallel processes easily, processes which are executed in an interval, as a service or after a specified amount of time. This module is very useful to help you to identify bottlenecks and to manage your main threads in a single place. read more...

Class Usage
Task Base class for all Tasks. This is the simplest of all
BlockingTask Executes a Task in blocking state (not background)
DelayedTask Executes a Task after N milliseconds
IntervalTask Executes a Task every N milliseconds
ParallelTask Executes several Tasks in a parallel pool
ServiceTask Executes a Task in background that is intended to run forever
Killable Interface to use to prepare task to be killed
@ TaskInfo Keeps track of statistics of a Task
@ TaskLoggable Interface to use to provide information to Log
@ TaskManager Controls all tasks (start, stop, restart)
@ TaskPool Group several Tasks and keep track of them
Tasks Generates report of all tasks and serves as entry point to add tasks to be monitored
@ ThreadPool Custom ThreadPoolExecutor object (Java management for threads)

Documentation / JavaDoc

term

Includes : core

Anything related to terminal is in this module (except AnsiColor, which is in core). It uses JLine to help you create interactive terminal (console) applications easily. It also contains some tools to display progress with colors. read more...

Class Usage
Consolable Interface to implement for any console application
Console Main console class which uses Consolable applications. It wraps jLine
ConsoleDefault Simple implementation of Consolable which provides common commands
@ MatchAnyCompleter Utility to find partial matches to commands
Progress Show a progress bar in a terminal (it has multiple implementations and options)
TableMaker Create tables for the terminal to display data in a nicely way

Documentation / JavaDoc

img

Includes : core

Classes for using Images (BufferedImage, File, FrameShot) and non-opencv related code, trying to keep dependencies to a minimum. It also includes common geometric operations. read more...

Class Usage
BuffImgTools Do operations on BufferedImages (rotate, crop, etc)
FileImgTools Do operations on image files (convenient wrapper around BuffImgTools)
Converter Convert from and to File, BufferedImage, byte array, etc.
FrameShot Represents a single frame (BufferedImage with name)
Metry Performs geometric operations (e.g, Trigonometry)

Documentation / JavaDoc

Dependencies

Starting from 2.8, this library no longer includes some dependencies, so you need to add them separately as you need. This was done to make this library more flexible by allowing you to choose your library versions, reduce the compilation time and your project jar size.

Below each module, I'm including the recommended version (the one used during compilation).

  • core : Groovy version is now up to you (required by any module).
    • org.codehaus.groovy:groovy-all:3.0.12
  • db : Database drivers need to be included (Choose the one(s) which match(es) your database(s)):
    • com.microsoft.sqlserver:mssql-jdbc:10.2.1.jre11
    • com.oracle.database.jdbc:ojdbc11:21.7.0.0
    • mysql:mysql-connector-java:8.0.30
    • org.apache.derby:derby:10.15.2.0
    • org.firebirdsql.jdbc:jaybird:4.0.7.java11
    • org.mariadb.jdbc:mariadb-java-client:3.0.6
    • org.postgresql:postgresql:42.5.0
    • org.xerial:sqlite-jdbc:3.39.4.1
  • etc :
    • Jedis (redis.clients:jedis:4.3.1)
    • BerkeleyDB (com.sleepycat:je:18.3.12)

The following modules are already included in the specified modules:

  • crypt
    • Bounty Castle (org.bouncycastle:bcprov-jdk15on:1.70, org.bouncycastle:bcpg-jdk15on:1.70, org.bouncycastle:bcprov-ext-jdk15on:1.70)
  • net
    • Apache Common Net (commons-net:commons-net:3.8.0)
    • JavaX Mail(com.sun.mail:javax.mail:1.6.2)
  • serial
    • JSSC library (org.scream3r:jssc:2.8.0)
  • term
    • JLine library (org.jline:jline:3.21.0)
  • web
    • Spark Framework (com.intellisrc:spark-core:2.9.4-unofficial-4)

Recommendations

If you need a library to build your web-based user interfaces (using javascript), check M2D2

Acknowledgments

Developed with IntelliJ Ultimate Edition. I would like to thank JetBrains for their support.

Package Rankings
Top 36.86% on Repo1.maven.org
Badges
Extracted from project README's
GPL Licence Open Source Love Maven Repository
Related Projects