article-background-1

 

If you already have keystore, you can skip step 1.

Step 1. Create keystore with private key in it.

keytool -genkey -alias server -keyalg RSA -keysize 2048 -keystore keystore.jks -dname "CN=p1, O=o1, L=Belgrade, ST=, C=RS"

Step 2. Create CSR based on keystore that you have.

keytool -certreq -alias server -file cerificateSigningRequestABC.csr -keystore keystore.jks

If you have map defined as for example HashMap:

Map<String, String> map = new HashMap<String, String>();

You can iterate through it using for loop on following way:

for (Map.Entry<String, String> entry : map.entrySet()) { 
System.out.println(entry.getKey() + "/" + entry.getValue()); 
}

 String.split() accepts a regular expression, so if you want to split by special character you need to escape . for it not to be considered as a regex meta character. For example, if you have the filename as:

SomeFile.jpg, to get its extension you’ll need to:

String[] fileNameParts = filename.split("\\.");

return fileNameParts[fileNameParts.length -1];

Oracle has licence restriction and there is no public Maven repository that provides Oracle JDBC driver. We have to install it manually into our local Maven repo. Steps:

1. Download Oracle JDBC driver from official Oracle website.

2. Install it in your local Maven repo using this console command:

mvn install:install-file -Dfile={Location/of/ojdbc.jar} -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

3. Add dependency to your pom.xml:

<dependency>

<groupId>com.oracle</groupId>

<artifactId>ojdbc6</artifactId>{jcomments on}

<version>11.2.0</version>

</dependency>

If you have a situation where you need to write data into the CSV file, one option should be using apache commons library. If you're using Maven, first you'll need to add dependency into pom.xml:

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.5</version>
</dependency>

Following code contains a solution for this issue:

package com.cloud.customers.utils;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

public class ExportDataToCsv {
	private static final String SAMPLE_CSV_FILE = "./sample.csv";
	public void exportDataToCsv() throws IOException {
		BufferedWriter writer = Files.newBufferedWriter(Paths.get(SAMPLE_CSV_FILE));
		CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT.withHeader("customerId", "locationId"));
		Map<String, String> data = new HashMap<String, String>();
		for (Map.Entry<String, String> entry : data.entrySet()) {
			csvPrinter.printRecord(Arrays.asList(entry.getKey(), entry.getValue()));
		}
		csvPrinter.flush();
	}
}

 You can find this code also on github.

There are many situations where you need to read from or write to .xlsx files. In this example, we'll show how to read data using apache-poi from file with data in the following format:

customerId locationId
23-dgf-45 4333-fdf-23
34-fsd-12 334g-43-44
... ...


If you're using Maven, it will be good to add it to your pom.xml file. Here I use version 3.9.

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>

Following code example reads data from file and returns Map where customerId is key and locationId is value.

 

package com.headsoft.cloud.tenants.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

Subcategories