forked from imsdev/ims-java-cobol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloWorldJava64.java
More file actions
121 lines (97 loc) · 3.23 KB
/
Copy pathHelloWorldJava64.java
File metadata and controls
121 lines (97 loc) · 3.23 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package mpr.apps;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;
public class HelloWorldJava64 {
/**
* To be called from COBOL using:
* CALL 'java.mpr.apps.HelloWorldJava64.sayHello1' using IN-DATA
* @param input
*/
public static void sayHello1(String input) {
String methodName = (new Object(){}).getClass().getEnclosingMethod().getName();
printHeader(methodName);
printGreeting(methodName);
System.out.println("The input variable input = " + input + "\n");
printFooter(methodName);
}
/**
* To be called from COBOL using manual JNI calls:
*
* @param inData A ByteBUffer we can modify
*/
public static void sayHello2(ByteBuffer inData) {
String methodName = (new Object(){}).getClass().getEnclosingMethod().getName();
printHeader(methodName);
try{
printGreeting(methodName);
// Make a copy of the contents of IN-DATA using the inData object
inData.position(0);
int inDataLenght = inData.capacity();
byte[] userBytes = new byte[inDataLenght];
inData.get(userBytes);
String transactionData = new String(userBytes, "Cp1047");
System.out.println("Transaction data: " + transactionData);
// Modify the contents of IN-DATA using the inData object
inData.position(0);
inData.put((new String("Java changed this!").getBytes("Cp1047")));
}
catch(IOException ioe){
System.out.println(ioe);
}
printFooter(methodName);
System.out.println(" ");
}
/**
* Print a greeting and the name of the method passed as input.
* @param methodName
*/
private static void printGreeting(String methodName){
System.out.println("Hello from Java!!");
System.out.println("Inside Java method: " + methodName);
}
/**
* Print a header block of text using the passed text.
* @param text the text to include in the header block.
*/
private static void printHeader(String text) {
printAsteriskBlock(text + " : Entry");
}
/**
* Print a footer block of text using the passed text.
* @param text the text to include in the footer block.
*/
private static void printFooter(String text) {
printAsteriskBlock(text + " : Exit");
}
/**
* Print text surounded by asterisks.
* @param text the text to suround with asterisks.
*/
private static void printAsteriskBlock(String text) {
System.out.println(" ");
System.out.println("******************************************************");
System.out.println("*** " + text);
System.out.println("******************************************************");
System.out.println(" ");
}
public static void main(String args[]) {
sayHello1("Carlos says Hi. 123456789*123456789*");
// String sampleData = "Carlos says Hi. 123456789*123456789*";
// byte[] sampleDataAsByteArray = sampleData.getBytes();
// ByteBuffer inData = ByteBuffer.allocate(sampleDataAsByteArray.length);
// inData.position(0);
// inData.put(sampleDataAsByteArray);
// sayHello2(inData);
//
// inData.position(0);
// int inDataLenght = inData.capacity();
// byte[] userBytes = new byte[inDataLenght];
// inData.get(userBytes);
// // $CA
// System.out.println("$CA original: \n" +sampleData);
// System.out.println("$CA modified: \n" + new String(userBytes));
// // $CA
}
}