Just fill in the names of the datasets/files you want hashed under the DATASET
DD.
Cheers,
Jantje.
//RUNMD5 JOB 'COMD.TMME.BATCH',
// CLASS=C,MSGCLASS=X,MSGLEVEL=(1,1),
// REGION=0M,
// NOTIFY=&SYSUID
//*
//*
//JAVA EXEC PROC=JVMPRC61,
// JAVACLS='com.jantje.MD5CheckSum',
// ARGS='//DD:DATASET',
// LOGLVL='+T'
//STDENV DD *
. /etc/profile
export JAVA_HOME=/jdk160-fp1/J6.0.1
export PATH=/bin:"${JAVA_HOME}"/bin
LIBPATH=/lib:/usr/lib:"${JAVA_HOME}"/bin
LIBPATH="$LIBPATH":"${JAVA_HOME}"/lib/s390
LIBPATH="$LIBPATH":"${JAVA_HOME}"/lib/s390/j9vm
LIBPATH="$LIBPATH":"${JAVA_HOME}"/bin/classic
export LIBPATH="$LIBPATH":
CLASSPATH=/u/users/JANTJE/MD5.jar:$CLASSPATH
export CLASSPATH
/*
//DATASET DD DATA,DLM=$$
JANTJE.PDS.CNTL(IEBGENER)
JANTJE.SEQ.VIJF100
/u/users/JANTJE/MD5/com/jantje/MD5CheckSum.java
$$
//
The JVMPRC61 proc is to invoke the JZOS machinery.
Source code of the'com.jantje.MD5CheckSum class:
package com.jantje;
import com.ibm.jzos.FileFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5CheckSum {
public static byte[] createChecksum(String filename) throws IOException,
NoSuchAlgorithmException {
InputStream inputStream = FileFactory.newInputStream(filename);
byte[] buffer = new byte[1024];
MessageDigest complete = MessageDigest.getInstance("MD5");
int numRead;
do {
numRead = inputStream.read(buffer);
if (numRead > 0) {
complete.update(buffer, 0, numRead);
}
} while (numRead != -1);
inputStream.close();
return complete.digest();
}
public static String getMD5Checksum(String filename) throws IOException,
NoSuchAlgorithmException {
byte[] b = createChecksum(filename);
String result = "";
for (int i = 0; i < b.length; i++) {
result +=
Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
}
return result;
}
public static void getMD5CheckSums(String parmFileName) throws
NoSuchAlgorithmException, IOException {
BufferedReader fileNames = null;
fileNames = FileFactory.newBufferedReader(parmFileName);
try {
String datasetName;
while ((datasetName = fileNames.readLine()) != null) {
System.out.print(String.format("%1$-50s", datasetName));
if (!datasetName.substring(0, 1).equals("/")) {
datasetName = "//'" + datasetName + "'";
}
try {
System.out.println(getMD5Checksum(datasetName));
} catch (IOException e) {
System.out.println("Not found");
}
}
} finally {
if (fileNames != null) fileNames.close();
}
}
public static void main(String args[]) {
try {
getMD5CheckSums(args[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
}
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN