Merge branch 'eugenp:master' into master
This commit is contained in:
commit
d31e8185f9
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
## Akka
|
||||
|
||||
This module contains modules about Akka.
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>akka-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>akka-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>akka-modules</artifactId>
|
||||
<name>akka-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>akka-http</module>
|
||||
<module>akka-streams</module>
|
||||
<module>spring-akka</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>akka-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -12,3 +12,4 @@ This module contains articles about Java 9 core features
|
|||
- [Easy Ways to Write a Java InputStream to an OutputStream](https://www.baeldung.com/java-inputstream-to-outputstream)
|
||||
- [Private Methods in Java Interfaces](https://www.baeldung.com/java-interface-private-methods)
|
||||
- [Java Scanner useDelimiter with Examples](https://www.baeldung.com/java-scanner-usedelimiter)
|
||||
- [Is There a Destructor in Java?](https://www.baeldung.com/java-destructor)
|
||||
|
|
|
@ -32,7 +32,7 @@ public class EmptyMapInitializer {
|
|||
return emptyMap;
|
||||
}
|
||||
|
||||
public Map createGenericEmptyMapUsingMapsObject() {
|
||||
public Map createGenericEmptyMapUsingGuavaMapsObject() {
|
||||
Map genericEmptyMap = Maps.<String, Integer>newHashMap();
|
||||
return genericEmptyMap;
|
||||
}
|
||||
|
@ -43,6 +43,11 @@ public class EmptyMapInitializer {
|
|||
return emptyMapUsingGuava;
|
||||
}
|
||||
|
||||
public static Map<String, String> createImmutableMapUsingGuava() {
|
||||
Map<String, String> emptyImmutableMapUsingGuava = ImmutableMap.of();
|
||||
return emptyImmutableMapUsingGuava;
|
||||
}
|
||||
|
||||
public SortedMap<String, String> createEmptySortedMap() {
|
||||
SortedMap<String, String> sortedMap = Collections.emptySortedMap();
|
||||
return sortedMap;
|
||||
|
|
|
@ -28,4 +28,9 @@ public class EmptyMapInitializerUnitTest {
|
|||
assertFalse(emptyMapUsingGuava.isEmpty());
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void givenImmutableEmptyMapUsingGuava_whenAddingEntries_throwsException() {
|
||||
Map<String, String> map = EmptyMapInitializer.createImmutableMapUsingGuava();
|
||||
map.put("key", "value");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,4 +9,4 @@ This module contains articles about conversions among Collection types and array
|
|||
- [Converting List to Map With a Custom Supplier](https://www.baeldung.com/list-to-map-supplier)
|
||||
- [Arrays.asList vs new ArrayList(Arrays.asList())](https://www.baeldung.com/java-arrays-aslist-vs-new-arraylist)
|
||||
- [Iterate Over a Set in Java](https://www.baeldung.com/java-iterate-set)
|
||||
- More articles: [[<-- prev]](../java-collections-conversions)
|
||||
- More articles: [[<-- prev]](../core-java-collections-conversions)
|
|
@ -3,9 +3,9 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-collections-conversions-2</artifactId>
|
||||
<artifactId>core-java-collections-conversions-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>java-collections-conversions-2</name>
|
||||
<name>core-java-collections-conversions-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -33,7 +33,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-collections-conversions-2</finalName>
|
||||
<finalName>core-java-collections-conversions-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
|
@ -12,4 +12,4 @@ This module contains articles about conversions among Collection types and array
|
|||
- [Java 8 Collectors toMap](https://www.baeldung.com/java-collectors-tomap)
|
||||
- [Converting Iterable to Collection in Java](https://www.baeldung.com/java-iterable-to-collection)
|
||||
- [Converting Iterator to List](https://www.baeldung.com/java-convert-iterator-to-list)
|
||||
- More articles: [[next -->]](../java-collections-conversions-2)
|
||||
- More articles: [[next -->]](../core-java-collections-conversions-2)
|
|
@ -3,9 +3,9 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-collections-conversions</artifactId>
|
||||
<artifactId>core-java-collections-conversions</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>java-collections-conversions</name>
|
||||
<name>core-java-collections-conversions</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -28,7 +28,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-collections-conversions</finalName>
|
||||
<finalName>core-java-collections-conversions</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
|
@ -8,3 +8,4 @@
|
|||
- [Java Map – keySet() vs. entrySet() vs. values() Methods](https://www.baeldung.com/java-map-entries-methods)
|
||||
- [Java IdentityHashMap Class and Its Use Cases](https://www.baeldung.com/java-identityhashmap)
|
||||
- [How to Invert a Map in Java](https://www.baeldung.com/java-invert-map)
|
||||
- More articles: [[<-- prev]](../core-java-collections-maps-4)
|
|
@ -3,9 +3,9 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-collections-maps-3</artifactId>
|
||||
<artifactId>core-java-collections-maps-5</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>java-collections-maps-3</name>
|
||||
<name>core-java-collections-maps-5</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
|
@ -12,4 +12,5 @@ This module contains articles about date operations in Java.
|
|||
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
|
||||
- [Getting the Week Number From Any Date](https://www.baeldung.com/java-get-week-number)
|
||||
- [Subtract Days from a Date in Java](https://www.baeldung.com/java-subtract-days-from-date)
|
||||
- [How to Calculate “Time Ago” in Java](https://www.baeldung.com/java-calculate-time-ago)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-date-operations-1)
|
||||
|
|
|
@ -7,7 +7,8 @@ import org.junit.Test;
|
|||
|
||||
public class TimeAgoCalculatorUnitTest {
|
||||
|
||||
@Test
|
||||
// fixing tests in BAEL-5647
|
||||
//@Test
|
||||
public void timeAgoByTimeGranularityTest() {
|
||||
long DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
|
||||
Assert.assertEquals("5 seconds ago", TimeAgoCalculator.calculateTimeAgoByTimeGranularity(new Date(System.currentTimeMillis() - (5 * 1000)), TimeGranularity.SECONDS));
|
||||
|
@ -20,7 +21,7 @@ public class TimeAgoCalculatorUnitTest {
|
|||
Assert.assertEquals("5 decades ago", TimeAgoCalculator.calculateTimeAgoByTimeGranularity(new Date(System.currentTimeMillis() - (5 * DAY_IN_MILLIS * 365 * 10)), TimeGranularity.DECADES));
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void humanFriendlyTimeAgoTest() {
|
||||
long DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
|
||||
Assert.assertEquals("moments ago", TimeAgoCalculator.calculateHumanFriendlyTimeAgo(new Date(System.currentTimeMillis() - (5 * 1000))));
|
||||
|
@ -33,14 +34,14 @@ public class TimeAgoCalculatorUnitTest {
|
|||
Assert.assertEquals("several decades ago", TimeAgoCalculator.calculateHumanFriendlyTimeAgo(new Date(System.currentTimeMillis() - (5 * DAY_IN_MILLIS * 365 * 10))));
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void calculateExactTimeAgoWithJodaTimeTest() {
|
||||
Assert.assertEquals("5 hours and 15 minutes and 3 seconds", TimeAgoCalculator.calculateExactTimeAgoWithJodaTime(new Date(System.currentTimeMillis() - (5 * 60 * 60 * 1000 + 15 * 60 * 1000 + 3 * 1000))));
|
||||
Assert.assertEquals("5 hours and 1 minute and 1 second", TimeAgoCalculator.calculateExactTimeAgoWithJodaTime(new Date(System.currentTimeMillis() - (5 * 60 * 60 * 1000 + 1 * 60 * 1000 + 1 * 1000))));
|
||||
Assert.assertEquals("2 days and 1 minute and 1 second", TimeAgoCalculator.calculateExactTimeAgoWithJodaTime(new Date(System.currentTimeMillis() - (2 * 24 * 60 * 60 * 1000 + 1 * 60 * 1000 + 1 * 1000))));
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void calculateHumanFriendlyTimeAgoWithJodaTimeTest() {
|
||||
long DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
|
||||
Assert.assertEquals("moments ago", TimeAgoCalculator.calculateHumanFriendlyTimeAgoWithJodaTime(new Date(System.currentTimeMillis() - (5 * 1000))));
|
||||
|
|
|
@ -9,7 +9,8 @@ import org.junit.Test;
|
|||
|
||||
public class TimeAgoCalculatorUnitTest {
|
||||
|
||||
@Test
|
||||
// fixing test in BAEL-5647
|
||||
//@Test
|
||||
public void calculateTimeAgoWithPeriodAndDurationTest() {
|
||||
long DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
|
||||
Assert.assertEquals("moments ago", TimeAgoCalculator.calculateTimeAgoWithPeriodAndDuration(LocalDateTime.ofInstant(Instant.ofEpochMilli(System.currentTimeMillis()), ZoneId.systemDefault()), ZoneId.systemDefault()));
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.baeldung.inputstreamtobase64;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
/**
|
||||
* Test the Stream to base64 conversion
|
||||
*/
|
||||
public class InputStreamToBase64UnitTest {
|
||||
|
||||
/**
|
||||
* Test stream to base64 conversion
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void givenABinaryInputStream_whenItIsConvertedToBase64_thenItCanBeDecoded() throws Exception {
|
||||
// given a binary input stream
|
||||
InputStream sourceStream = getClass().getClassLoader().getResourceAsStream("logo.png");
|
||||
byte[] sourceBytes = IOUtils.toByteArray(sourceStream);
|
||||
|
||||
// when it is converted to base64
|
||||
String encodedString = Base64.getEncoder().encodeToString(sourceBytes);
|
||||
assertNotNull(encodedString);
|
||||
|
||||
// then it can be decoded
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
|
||||
assertNotNull(decodedBytes);
|
||||
assertTrue(decodedBytes.length == sourceBytes.length);
|
||||
assertTrue(calculateChecksum(decodedBytes) == calculateChecksum(sourceBytes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a checksum
|
||||
* @param bytes array of bytes to check
|
||||
* @return the total sum of all bytes
|
||||
*/
|
||||
private int calculateChecksum(byte[] bytes) {
|
||||
int checksum = 0;
|
||||
for(int index=0; index < bytes.length; index++) {
|
||||
checksum+=bytes[index];
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
|
@ -8,4 +8,5 @@ This module contains articles about JAR files
|
|||
- [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class)
|
||||
- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar)
|
||||
- [Get Names of Classes Inside a JAR File](https://www.baeldung.com/jar-file-get-class-names)
|
||||
[Find All Jars Containing Given Class](https://baeldung.com/find-all-jars-containing-given-class/)
|
||||
- [Find All Jars Containing Given Class](https://baeldung.com/find-all-jars-containing-given-class/)
|
||||
- [Creating JAR Files Programmatically](https://www.baeldung.com/jar-create-programatically)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.createjar;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.jar.*;
|
||||
import com.baeldung.createjar.JarTool;
|
||||
|
||||
public class Driver {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
JarTool tool = new JarTool();
|
||||
tool.startManifest();
|
||||
tool.addToManifest("Main-Class", "com.baeldung.createjar.HelloWorld");
|
||||
JarOutputStream target = tool.openJar("HelloWorld.jar");
|
||||
|
||||
tool.addFile(target, System.getProperty("user.dir") + "\\src\\main\\java", System.getProperty("user.dir") + "\\src\\main\\java\\com\\baeldung\\createjar\\HelloWorld.class");
|
||||
target.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.createjar;
|
||||
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.baeldung.createjar;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.jar.*;
|
||||
|
||||
public class JarTool {
|
||||
private Manifest manifest = new Manifest();
|
||||
|
||||
public void addToManifest(String key, String value) {
|
||||
manifest.getMainAttributes()
|
||||
.put(new Attributes.Name(key), value);
|
||||
}
|
||||
|
||||
public void addDirectoryEntry(JarOutputStream target, String parentPath, File dir) throws IOException {
|
||||
String remaining = "";
|
||||
if (parentPath.endsWith(File.separator))
|
||||
remaining = dir.getAbsolutePath()
|
||||
.substring(parentPath.length());
|
||||
else
|
||||
remaining = dir.getAbsolutePath()
|
||||
.substring(parentPath.length() + 1);
|
||||
String name = remaining.replace("\\", "/");
|
||||
if (!name.endsWith("/"))
|
||||
name += "/";
|
||||
JarEntry entry = new JarEntry(name);
|
||||
entry.setTime(dir.lastModified());
|
||||
target.putNextEntry(entry);
|
||||
target.closeEntry();
|
||||
}
|
||||
|
||||
public void addFile(JarOutputStream target, String rootPath, String source) throws IOException {
|
||||
BufferedInputStream in = null;
|
||||
String remaining = "";
|
||||
if (rootPath.endsWith(File.separator))
|
||||
remaining = source.substring(rootPath.length());
|
||||
else
|
||||
remaining = source.substring(rootPath.length() + 1);
|
||||
String name = remaining.replace("\\", "/");
|
||||
JarEntry entry = new JarEntry(name);
|
||||
entry.setTime(new File(source).lastModified());
|
||||
target.putNextEntry(entry);
|
||||
in = new BufferedInputStream(new FileInputStream(source));
|
||||
byte[] buffer = new byte[1024];
|
||||
while (true) {
|
||||
int count = in.read(buffer);
|
||||
if (count == -1)
|
||||
break;
|
||||
target.write(buffer, 0, count);
|
||||
}
|
||||
target.closeEntry();
|
||||
in.close();
|
||||
}
|
||||
|
||||
public JarOutputStream openJar(String jarFile) throws IOException {
|
||||
JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest);
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setMainClass(String mainFQCN) {
|
||||
if (mainFQCN != null && !mainFQCN.equals(""))
|
||||
manifest.getMainAttributes()
|
||||
.put(Attributes.Name.MAIN_CLASS, mainFQCN);
|
||||
}
|
||||
|
||||
public void startManifest() {
|
||||
manifest.getMainAttributes()
|
||||
.put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
||||
}
|
||||
}
|
|
@ -13,4 +13,4 @@ This module contains articles about numbers in Java.
|
|||
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
|
||||
- [Finding the Least Common Multiple in Java](https://www.baeldung.com/java-least-common-multiple)
|
||||
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
|
||||
- More articles: [[<-- prev]](../java-numbers) [[next -->]](../java-numbers-3)
|
||||
- More articles: [[<-- prev]](../core-java-numbers) [[next -->]](../core-java-numbers-3)
|
|
@ -3,9 +3,9 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-numbers-2</artifactId>
|
||||
<artifactId>core-java-numbers-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>java-numbers-2</name>
|
||||
<name>core-java-numbers-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -28,7 +28,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-numbers-2</finalName>
|
||||
<finalName>core-java-numbers-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue