JavaUtils is a small library to ease programming with Java.
Gradle:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}dependencies {
implementation 'com.github.alexsgi:java-utils:VERSION'
}Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.alexsgi</groupId>
<artifactId>java-utils</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
Run something delayed:
FutureTaskExecutor.runDelayed(Runnablerunnable, intdelayInMilliSeconds);FutureTaskExecutor.runDelayed(newRunnable(){
@Overridepublicvoidrun(){
System.out.println("This message will be printed after 5000 ms");
}
}, 5000);FutureTaskExecutor.runDelayed(Runnablerunnable, intdelayInMilliSeconds, booleanisTerminable);isTerminable : (default: false) if set to false, the timer will stop properly on finish of the runnable,
otherwise (if set to true) the timer can be interrupted (e.g. by the main method).
SHA2-512:
Stringsha2_512Hashed = Cryptography.hashSHA2("Example text");SHA3-512:
Stringsha3_512Hashed = Cryptography.hashSHA3("Example");Base64-Encoding:
Stringbase64Encoded = Cryptography.base64Encryption("Example of the example");Change the hash length (default: 512) :
Cryptography.setHashLength(inthashLength);Cryptography.setHashLength(256);Get the hash length :
inthashLength = Cryptography.getHashLength();Reset the hash length (default: 512) :
Cryptography.resetHashLength();Get all drives :
Drive[] drives = SystemInfo.getAllDrives();
for(Drivedrive : drives){
System.out.println(drive.getDriveName());
System.out.println(drive.getDriveLetter());
System.out.println(drive.getDriveDescription());
}Change the text color or even the background color via ANSI codes :
StringtextFormatted = TextColor.formatColor(Stringinput, Stringcolor);
StringbackgroundFormatted = TextColor.formatBackground(Stringinput, StringbackgroundColor);
StringbothFormated = TextColor.formatColors(Stringinput, Stringcolor, StringbackgroundColor);Following options are available :
RESETBLACKREDGREENYELLOWBLUEPURPLECYANWHITEBLACK_BACKGROUNDRED_BACKGROUNDGREEN_BACKGROUNDYELLOW_BACKGROUNDBLUE_BACKGROUNDPURPLE_BACKGROUNDCYAN_BACKGROUNDWHITE_BACKGROUNDExample :
TextColor.formatColor("Example", TextColor.CYAN);
TextColor.formatBackground("Example", TextColor.CYAN_BACKGROUND);
TextColor.formatColors("Example", TextColor.CYAN, TextColor.CYAN_BACKGROUND);Take a screenshot (PNG):
AdvImage.takeScreenshot(File nameOfTheScreenshot);
Filefile = newFile("C:\\Users\\Public\\Desktop\\screenshot.png");JPEG screenshots:
AdvImage.takeJPEGScreenshot(File nameOfTheScreenshot);
You want to take multiple screenshots?
AdvImage.takeScrenshots(File path, int amount, int delay);
AdvImage.takeScrenshots(File path, int amount, int delay, boolean inNewThread);
Notice: the input file needs to be a directory
Create many threads with the same runnable :
MultiThreads.createThreads(Runnablerunnable, intamountOfThreads);Start all threads :
MultiThreads.startThreads();Interrupt all Threads :
MultiThreads.interruptThreads();Clear all Threads :
MultiThreads.clearThreads();Get current amount of Threads :
intamount = MultiThreads.getThreadAmount();Some tools for Strings :
Check if a String contains at least one of the params :
StringUtils.containsOneOf(Stringsrc, String... params);Check if a String contains all of the params :
StringUtils.containsAll(Stringsrc, String... params)