-
Download the gradle binary from the following address:
https://services.gradle.org/distributions/
For example gradle-7.4-all.zip.
-
Place the downloaded gradle binary to the gradle/wrapper directory of the gradle project.
-
Update the wrapper configuration (i.e. gradle/wrapper/gradle-wrapper.properties) like the following:
If you've downloaded gradle-7.4-all.zip binary from step 1.
distributionBase=PROJECT distributionPath=wrapper/dists distributionUrl=gradle-7.4-all.zip zipStoreBase=PROJECT zipStorePath=wrapper/dists
Author: ron (Page 13 of 34)
The UTF-16LE base64 encoding is compatible to be used with powershell's encoded command.
Encoding
//The text to encode.
var command = "Write-Output \"Hello World\"";
var encodedString = Base64.getEncoder().encodeToString(command.getBytes(StandardCharsets.UTF_16LE));
System.out.printf("Base64: %s%n", encodedString);
Output
Base64: VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIAAiAEgAZQBsAGwAbwAgAFcAbwByAGwAZAAiAA==
The preceding output can be used with powershell like the following:
powershell -encodedcommand VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIAAiAEgAZQBsAGwAbwAgAFcAbwByAGwAZAAiAA==
Decoding
//The base64 text to decode.
var base64="VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIAAiAEgAZQBsAGwAbwAgAFcAbwByAGwAZAAiAA==";
byte[] decodedBytes = Base64.getDecoder().decode(base64);
String decodedString = new String(decodedBytes, StandardCharsets.UTF_16LE);
System.out.printf("Decoded: %s%n", decodedString);
Output
Decoded: Write-Output "Hello World"
Sample codes for mocking a static with Mockito.
The StringUtil class is a very trivial class that converts the text to all capitalized.
StringUtil class
public final class StringUtil {
private StringUtil() {}
public static String upperCase(String text) {
return text.toUpperCase();
}
}
Mocking the StringUtil.upperCase method
Stubbing the StringUtil.upperCase method to return test if test is passed as argument.
Dependencies Required
org.junit.jupiter:junit-jupiter-engine:5.8.2
org.mockito:mockito-inline:4.4.0
StringUtilTest class
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
public class StringUtilTest {
@Test
void staticMethod() {
try (var utilities = mockStatic(StringUtil.class)) {
utilities.when(() -> StringUtil.upperCase("test")).thenReturn("test");
assertEquals("test", StringUtil.upperCase("test"));
}
}
}
var dirPath = Paths.get("C:\\tmp", "sample"); //The path to be tested.
if (dirPath.toFile().isDirectory()) { //Check if the directory exists.
try (Stream<Path> entries = Files.list(dirPath)) {
if (entries.findFirst().isEmpty()) {
System.out.printf("%s is empty.", dirPath);
}
}
}
Listing the Available Random Algorithms
System.out.printf("%-13s| %s\n-------------|---------------------\n", "Group", "Name");
java.util.random.RandomGeneratorFactory.all()
.sorted(java.util.Comparator.comparing(java.util.random.RandomGeneratorFactory::name))
.forEach(factory -> System.out.printf("%-13s| %s\n", factory.group(), factory.name()));
The output is similar to the following:
Group | Name
-------------|---------------------
LXM | L128X1024MixRandom
LXM | L128X128MixRandom
LXM | L128X256MixRandom
LXM | L32X64MixRandom
LXM | L64X1024MixRandom
LXM | L64X128MixRandom
LXM | L64X128StarStarRandom
LXM | L64X256MixRandom
Legacy | Random
Legacy | SecureRandom
Legacy | SplittableRandom
Xoroshiro | Xoroshiro128PlusPlus
Xoshiro | Xoshiro256PlusPlus
Check from the following address on how to choose which algorithm to choose:
Creating an instance of RandomGenerator
The default algorithm (i.e. L32X64MixRandom)
var generator = java.util.random.RandomGenerator.getDefault();
The specific algorithm (e.g. L64X128MixRandom)
var generator = java.util.random.RandomGenerator.of("L64X128MixRandom");
Use the static method RandomGenerator.of and pass the name of the algorithm.
Generating Random Number
Use one of the following instance methods of the RandomGenerator class:
- nextDouble()
- nextDouble(double bound)
- nextDouble(double origin, double bound)
- nextFloat()
- nextFloat(float bound)
- nextFloat(float origin, float bound)
- nextInt()
- nextInt(int bound)
- nextInt(int origin, int bound)
- nextLong()
- nextLong(long bound)
- nextLong(long origin, long bound)
The origin parameter is inclusive and bound parameter is exclusive.
Example using a classic random algorithm
var generator = java.util.random.RandomGenerator.of("Random");
System.out.println(generator.nextInt());
The output is a random integer number.
Generating Random Number Using Streams
Use one of the following instance methods of RandomGenerators class to create streams:
- doubles()
- doubles(double origin, double bound)
- doubles(long streamSize)
- doubles(long streamSize, double origin, double bound)
- ints()
- ints(int origin, int bound)
- ints(long streamSize)
- ints(long streamSize, int origin, int bound)
- longs()
- longs(long origin, long bound)
- longs(long streamSize)
- longs(long streamSize, long origin, long bound)
The origin parameter is inclusive and bound parameter is exclusive.
Example using a classic random algorithm
var generator = java.util.random.RandomGenerator.of("Random");
var randomInt = generator.ints(100, 1, 100)
.filter(number -> number % 2 == 0 )
.findFirst();
randomInt.ifPresent(System.out::println);
The output is a random integer number.
-
Create settings.gradle file with the following content:
rootProject.name = 'download-dependecies'
-
Create build.gradle file with the following content:
plugins { id 'application' } group 'xyz.ronella.gradle' version '1.0.0' repositories { mavenCentral() } dependencies { //Add all the target dependencies here implementation 'org.apache.poi:poi:3.5-FINAL' } task download(group: 'resolver') { doFirst { ant.delete(dir: 'libs') ant.mkdir(dir: 'libs') } doLast { copy { from sourceSets.main.runtimeClasspath into 'libs/' } def outputFile = "${project.buildDir}\\${project.name}-${version}.zip" ant.zip(basedir: "${file('libs')}", destfile: "${outputFile}", excludes: '*.class') println "Output: ${outputFile}" ant.delete(dir: 'libs') } }
-
Run the following gradle command:
gradle download
If you are using the gradle wrapper, use the following command:
gradlew download
Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.
public sealed interface IAnimal
permits AquaticAnimal, LandAnimal {
String lifespan();
}
Notice the use of the sealed modifier and permits keyword. The sealed modifier indicates that the class or interface is restricted. The permit keyword indicates which classes (or interfaces) can implement (or extends) it. Thus, the sealed modifier and the permit keyword must be used together.
public sealed abstract class AquaticAnimal implements IAnimal permits SeaTurtle {
}
The class (or interface) that can implement (or extend) a sealed interface (or class) must have one of the following modifiers:
- sealed
- non-sealed
- final
public non-sealed abstract class LandAnimal implements IAnimal {
}
Using the non-sealed modifier indicates that this class can be extended without restriction.
public sealed class Dog extends LandAnimal permits Boxer {
@Override
public String lifespan() {
return "10 - 13 years";
}
}
Limiting the hierarchy of Dog class to just Boxer class.
public final class Boxer extends Dog {
@Override
public String lifespan() {
return "10 - 12 years";
}
}
The final implementation of the Dog class.
public class Cat extends LandAnimal {
@Override
public String lifespan() {
return "12 - 18 years";
}
}
Since LandAnimal is non-sealed abstract class, it can be inherited without restriction.
public final class SeaTurtle extends AquaticAnimal {
@Override
public String lifespan() {
return "Up to 50 years or more";
}
}
SeaTurtle is the only class that can implement AquaticAnimal. Because this the only class permitted in the AquaticAnimal definition.
Identifying your Custodian member and Wallet Payment IDs [^1]
On the brave browser where you've successfully verified an uphold wallet.
-
Type in on your brave browser address bar the following:
brave://rewards-internals
-
Select the General info tab.
-
Note the Wallet payment ID from the the Wallet info section.
Include this information in the description of the request form.
-
Note the Custodian member ID from the External wallet info section.
-
Create a request to Wallet Unlinking Request form
[^1]: How can i verify my browser on a new device have reached the lifetime limit
Issue
Pinging any known working internet address is returning the following message:
Temporary failure in name resolution
Example
Pinging www.google.com as follows:
ping: www.google.com: Temporary failure in name resolution
Resolution
Check where you /etc/resolve.conf is pointing using the following command:
ls -al /etc | grep resolv.conf
If it is not pointing to /run/systemd/resolve/resolv.conf. Do the following:
sudo rm /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
sudo systemctl restart systemd-resolved.service
The following java code extracts the group, artifact and version using regex capture groups:
import java.util.regex.Pattern;
public class Main {
public static void main(String ... args) {
//Text to extract the group, artifact and version
var text = "org.junit.jupiter:junit-jupiter-api:5.7.0";
//Regex capture groups for Group:Artifact:Version
var pattern = "(.*):(.*):(.*)";
var compiledPattern = Pattern.compile(pattern);
var matcher = compiledPattern.matcher(text);
if (matcher.find( )) {
System.out.println("Whole text: " + matcher.group(0) );
System.out.println("Group: " + matcher.group(1) );
System.out.println("Artifact: " + matcher.group(2) );
System.out.println("Version: " + matcher.group(3) );
} else {
System.out.println("NO MATCH");
}
}
}
Output
Whole text: org.junit.jupiter:junit-jupiter-api:5.7.0
Group: org.junit.jupiter
Artifact: junit-jupiter-api
Version: 5.7.0
Recent Comments