1 package net.sf.cobol2j.examples;
2
3 import net.sf.cobol2j.FileFormat;
4 import net.sf.cobol2j.FileFormatException;
5 import net.sf.cobol2j.RecordParseException;
6 import net.sf.cobol2j.RecordSet;
7 import net.sf.cobol2j.RecordWriter;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import java.io.FileInputStream;
13 import java.io.FileNotFoundException;
14 import java.io.IOException;
15
16 import javax.xml.bind.JAXBContext;
17 import javax.xml.bind.JAXBException;
18 import javax.xml.bind.Unmarshaller;
19
20
21 public class Dat2dat {
22 private static Log log = LogFactory.getLog(Dat2dat.class);
23
24 public static void main(String[] args)
25 throws FileFormatException, JAXBException, FileNotFoundException,
26 IOException, RecordParseException {
27 String xc2jsrc = args[0];
28 String xc2jtarget = args[1];
29 JAXBContext context = JAXBContext.newInstance("net.sf.cobol2j");
30 Unmarshaller unmarshaller = context.createUnmarshaller();
31 Object in = unmarshaller.unmarshal(new FileInputStream(xc2jsrc));
32 Object out = unmarshaller.unmarshal(new FileInputStream(xc2jtarget));
33 FileFormat fFin = (FileFormat) in;
34 FileFormat fFout = (FileFormat) out;
35 RecordSet rset = new RecordSet(System.in, fFin);
36
37 try {
38 RecordWriter rw = new RecordWriter(System.out, fFout);
39
40 while (rset.hasNext())
41 rw.writeRecord(rset.next());
42 } catch (FileFormatException ex) {
43 ex.printStackTrace();
44 } catch (Exception ex) {
45 ex.printStackTrace();
46 }
47 }
48 }