<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://wiki.chongtin.com/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="https://wiki.chongtin.com/feed.php">
        <title>Tutorial Site java</title>
        <description></description>
        <link>https://wiki.chongtin.com/</link>
        <image rdf:resource="https://wiki.chongtin.com/ttps://wiki.chongtin.com/lib/tpl/bootstrap3/images/favicon.ico" />
       <dc:date>2026-04-09T00:48:36+00:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/apache_poi_check_if_file_contains_macros?do=revisions&amp;rev=1550118747"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/basic_gson?do=revisions&amp;rev=1565679361"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/byte_to_file?do=revisions&amp;rev=1592193027"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/calling_native_windows_dll_api_with_jna?do=revisions&amp;rev=1596015931"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/checking_memory_allocation?do=revisions&amp;rev=1576461587"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/file_to_string?do=revisions&amp;rev=1607574548"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/jasper_report?do=revisions&amp;rev=1546933679"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/levenshtein_distance?do=revisions&amp;rev=1626942610"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/resize_image_with_imageio_and_graphics2d?do=revisions&amp;rev=1592191655"/>
                <rdf:li rdf:resource="https://wiki.chongtin.com/java/setting_truststore_and_keystore_in_runtime?do=revisions&amp;rev=1571369613"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="https://wiki.chongtin.com/ttps://wiki.chongtin.com/lib/tpl/bootstrap3/images/favicon.ico">
        <title>Tutorial Site</title>
        <link>https://wiki.chongtin.com/</link>
        <url>https://wiki.chongtin.com/ttps://wiki.chongtin.com/lib/tpl/bootstrap3/images/favicon.ico</url>
    </image>
    <item rdf:about="https://wiki.chongtin.com/java/apache_poi_check_if_file_contains_macros?do=revisions&amp;rev=1550118747">
        <dc:format>text/html</dc:format>
        <dc:date>2019-02-14T12:32:27+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Apache POI Check if File Contains Macros</title>
        <link>https://wiki.chongtin.com/java/apache_poi_check_if_file_contains_macros?do=revisions&amp;rev=1550118747</link>
        <description>Apache POI Check if File Contains Macros

This code should work for all office file. In this code, we test the file 1.doc in the project root directory. Requirement: POI 3.15 or above. 


import org.apache.poi.poifs.macros.VBAMacroReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

public class Main {
    private static boolean hasVBA(InputStream inputStream) throws IOException {
        boolean returnVal = f…</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/basic_gson?do=revisions&amp;rev=1565679361">
        <dc:format>text/html</dc:format>
        <dc:date>2019-08-13T14:56:01+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Basic Gson</title>
        <link>https://wiki.chongtin.com/java/basic_gson?do=revisions&amp;rev=1565679361</link>
        <description>Basic Gson

Add Gson Dependency


&lt;dependency&gt;
    &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
    &lt;artifactId&gt;gson&lt;/artifactId&gt;
    &lt;version&gt;2.8.5&lt;/version&gt;
&lt;/dependency&gt;


Assumption

Assume we have a Company class, and a Staff class such that Company has a name, a start date, and a list of staff, and the staff has a name, and a salary field. We use the following code to create the Java objects.</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/byte_to_file?do=revisions&amp;rev=1592193027">
        <dc:format>text/html</dc:format>
        <dc:date>2020-06-15T11:50:27+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Byte Array to File</title>
        <link>https://wiki.chongtin.com/java/byte_to_file?do=revisions&amp;rev=1592193027</link>
        <description>Byte Array to File

Classic Way


    public static void main(String[] args) {
        byte[] b = &quot;ABCDEFGHIJK&quot;.getBytes();
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(&quot;./out.txt&quot;);
            fileOutputStream.write(b);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            if (fileOutputStream !…</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/calling_native_windows_dll_api_with_jna?do=revisions&amp;rev=1596015931">
        <dc:format>text/html</dc:format>
        <dc:date>2020-07-29T17:45:31+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Calling Native Windows DLL API with JNA</title>
        <link>https://wiki.chongtin.com/java/calling_native_windows_dll_api_with_jna?do=revisions&amp;rev=1596015931</link>
        <description>Calling Native Windows DLL API with JNA

	*  Include the JNA library in your project
	*  Create an interface that extents com.sun.jna.Library with the prototypes of the functions your need to call
	*  Copy the DLL file to your project.
	*  Load the library (in this case dll) with com.sun.jna.Native</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/checking_memory_allocation?do=revisions&amp;rev=1576461587">
        <dc:format>text/html</dc:format>
        <dc:date>2019-12-16T09:59:47+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Checking Memory Allocation</title>
        <link>https://wiki.chongtin.com/java/checking_memory_allocation?do=revisions&amp;rev=1576461587</link>
        <description>Checking Memory Allocation

We can run the following code to estimate Java VM memory usage in run-time: (Original from StackOverFlow Jeremy answer &lt;https://stackoverflow.com/questions/74674/how-do-i-check-cpu-and-memory-usage-in-java&gt; with a little modification for console)

To estimate the memory usage of a section, we can user 'System.gc()</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/file_to_string?do=revisions&amp;rev=1607574548">
        <dc:format>text/html</dc:format>
        <dc:date>2020-12-10T12:29:08+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>File to String</title>
        <link>https://wiki.chongtin.com/java/file_to_string?do=revisions&amp;rev=1607574548</link>
        <description>File to String

Read the Whole File

Change YOUR_FILE to your actual file. You might want to change to charset for your file.


class Scratch {
    static String readFile(String path, Charset encoding)
            throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }

    public static void main(String[] args) {
        try {
            String s = readFile(&quot;404357  1 - SOP AF WT 2019.json&quot;, Charset.defaultCharset()…</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/jasper_report?do=revisions&amp;rev=1546933679">
        <dc:format>text/html</dc:format>
        <dc:date>2019-01-08T15:47:59+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Jasper Report</title>
        <link>https://wiki.chongtin.com/java/jasper_report?do=revisions&amp;rev=1546933679</link>
        <description>Jasper Report

Jasper report can help us to export a pdf file in Java. To make it simple, we will only focus on data source with JRBeanCollectionDataSource, and use only the Text Field, and Static Text basic elements to build this report.

Code

Assume we have already created a jasper template</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/levenshtein_distance?do=revisions&amp;rev=1626942610">
        <dc:format>text/html</dc:format>
        <dc:date>2021-07-22T16:30:10+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Levenshtein Distance</title>
        <link>https://wiki.chongtin.com/java/levenshtein_distance?do=revisions&amp;rev=1626942610</link>
        <description>Levenshtein Distance

Levenshtein Distance is a method to check the similarity of wo string. If the string is very similar, we will get a small value for the distance. If the two strings are completely off, we get the value of max string lenth as the distance.</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/resize_image_with_imageio_and_graphics2d?do=revisions&amp;rev=1592191655">
        <dc:format>text/html</dc:format>
        <dc:date>2020-06-15T11:27:35+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Resize Image with ImageIO and Graphics2D</title>
        <link>https://wiki.chongtin.com/java/resize_image_with_imageio_and_graphics2d?do=revisions&amp;rev=1592191655</link>
        <description>Resize Image with ImageIO and Graphics2D

Here is how we do it. Note that the try catch exception is omitted here, you need to do it yourself.

	*  Read the image file from storage as InputStream
	*  Read it as BufferedImage
	*  Create a new BufferedImage</description>
    </item>
    <item rdf:about="https://wiki.chongtin.com/java/setting_truststore_and_keystore_in_runtime?do=revisions&amp;rev=1571369613">
        <dc:format>text/html</dc:format>
        <dc:date>2019-10-18T11:33:33+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Setting TrustStore and KeyStore in Runtime</title>
        <link>https://wiki.chongtin.com/java/setting_truststore_and_keystore_in_runtime?do=revisions&amp;rev=1571369613</link>
        <description>Setting TrustStore and KeyStore in Runtime

Sometime we might not want to mess up the Java JRE/JDK trust store and key store while we are testing some crazy shit like self-signed cert. We can do that in our application during running. Here is the code to do it:</description>
    </item>
</rdf:RDF>
