java-20349: move pre-jpms module to core-java-9 module
This commit is contained in:
@@ -12,3 +12,4 @@ This module contains articles about Java 9 core features
|
||||
- [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)
|
||||
- [Java 9 Migration Issues and Resolutions](https://www.baeldung.com/java-9-migration-issue)
|
||||
@@ -46,6 +46,11 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>${javax.xml.bind.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -58,6 +63,9 @@
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
<compilerArgs>
|
||||
<arg>--add-exports=java.base/com.sun.crypto.provider=ALL-UNNAMED</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
@@ -74,6 +82,7 @@
|
||||
<awaitility.version>1.7.0</awaitility.version>
|
||||
<maven.compiler.source>1.9</maven.compiler.source>
|
||||
<maven.compiler.target>1.9</maven.compiler.target>
|
||||
<javax.xml.bind.version>2.4.0-b180725.0427</javax.xml.bind.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.baeldung.java9.prejpms;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.lang.StackWalker.Option;
|
||||
import java.lang.StackWalker.StackFrame;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import com.sun.crypto.provider.SunJCE;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
getCrytpographyProviderName();
|
||||
getCallStackClassNames();
|
||||
getXmlFromObject(new Book(100, "Java Modules Architecture"));
|
||||
getBase64EncodedString("Java");
|
||||
}
|
||||
|
||||
private static void getCrytpographyProviderName() {
|
||||
try {
|
||||
LOGGER.info("1. JCE Provider Name: {}\n", new SunJCE().getName());
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void getCallStackClassNames() {
|
||||
try {
|
||||
StringBuffer sbStack = new StringBuffer();
|
||||
AtomicInteger i = new AtomicInteger(0);
|
||||
StackWalker.getInstance((Option.RETAIN_CLASS_REFERENCE))
|
||||
.walk(s -> s.map(StackFrame::getDeclaringClass)
|
||||
.map(e -> {
|
||||
i.getAndIncrement();
|
||||
return e.getName();
|
||||
}))
|
||||
.forEach(name -> sbStack.append(String.format("%d. %s \n", i.get(), name)));
|
||||
LOGGER.info("2. Call Stack:\n{}", sbStack);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void getXmlFromObject(Book book) {
|
||||
try {
|
||||
Marshaller marshallerObj = JAXBContext.newInstance(Book.class)
|
||||
.createMarshaller();
|
||||
marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
marshallerObj.marshal(book, sw);
|
||||
LOGGER.info("3. Xml for Book object:\n{}", sw);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void getBase64EncodedString(String inputString) {
|
||||
try {
|
||||
String encodedString = new String(Base64.getEncoder()
|
||||
.encode(inputString.getBytes()));
|
||||
LOGGER.info("4. Base Encoded String: {}", encodedString);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.java9.prejpms;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "book")
|
||||
public class Book {
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
public Book() {
|
||||
}
|
||||
|
||||
public Book(long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement(name = "title")
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user