-
Notifications
You must be signed in to change notification settings - Fork 3
/
ApplicationWithCsvInput.java
61 lines (50 loc) · 1.95 KB
/
ApplicationWithCsvInput.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package software.xdev;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.opencsv.exceptions.CsvValidationException;
import software.xdev.bzst.dip.client.BzstDipClient;
import software.xdev.bzst.dip.client.exception.HttpStatusCodeNotExceptedException;
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfiguration;
import software.xdev.bzst.dip.client.model.message.BzstDipCompleteResult;
@SuppressWarnings("checkstyle:MagicNumber")
public final class ApplicationWithCsvInput
{
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationWithCsvInput.class);
public static void main(final String[] args)
throws InterruptedException, HttpStatusCodeNotExceptedException, IOException, CsvValidationException
{
final BzstDipConfiguration configuration = Application.createConfiguration();
final String csvData = getResourceFileAsString("DemoCsvData.csv");
final BzstDipClient bzstDipClient = new BzstDipClient(configuration);
final BzstDipCompleteResult bzstDipCompleteResult = bzstDipClient.sendDipAndQueryResult(csvData);
LOGGER.info(
"Sending dip message with transfer number {} {}",
bzstDipCompleteResult.dataTransferNumber(),
bzstDipCompleteResult.isSuccessful() ? "was successful." : "has failed!"
);
}
private static String getResourceFileAsString(final String fileName) throws IOException
{
final ClassLoader classLoader = ClassLoader.getSystemClassLoader();
try(final InputStream is = classLoader.getResourceAsStream(fileName))
{
if(is == null)
{
return null;
}
try(final InputStreamReader isr = new InputStreamReader(is);
final BufferedReader reader = new BufferedReader(isr))
{
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
}
}
}
private ApplicationWithCsvInput()
{
}
}