9bf6b062fd59d33c6343b7fafd5a7dd989fa6e64
[marc4j.git] / src / org / marc4j / samples / Marc8ToMarcXmlExample.java
1 // $Id: Marc8ToMarcXmlExample.java,v 1.1 2006/08/04 12:39:58 bpeters Exp $\r
2 /**\r
3  * Copyright (C) 2002-2006 Bas Peters\r
4  *\r
5  * This file is part of MARC4J\r
6  *\r
7  * MARC4J is free software; you can redistribute it and/or\r
8  * modify it under the terms of the GNU Lesser General Public \r
9  * License as published by the Free Software Foundation; either \r
10  * version 2.1 of the License, or (at your option) any later version.\r
11  *\r
12  * MARC4J is distributed in the hope that it will be useful,\r
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
15  * Lesser General Public License for more details.\r
16  *\r
17  * You should have received a copy of the GNU Lesser General Public \r
18  * License along with MARC4J; if not, write to the Free Software\r
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
20  */\r
21 package org.marc4j.samples;\r
22 \r
23 import java.io.File;\r
24 import java.io.FileInputStream;\r
25 import java.io.InputStream;\r
26 import java.io.OutputStream;\r
27 \r
28 import org.marc4j.MarcReader;\r
29 import org.marc4j.MarcStreamReader;\r
30 import org.marc4j.MarcWriter;\r
31 import org.marc4j.MarcXmlWriter;\r
32 import org.marc4j.converter.impl.AnselToUnicode;\r
33 import org.marc4j.marc.Record;\r
34 \r
35 /**\r
36  * Writes MARC XML in UTF-8 to standard output.\r
37  * \r
38  * @author Bas Peters\r
39  * @version $Revision: 1.1 $\r
40  */\r
41 public class Marc8ToMarcXmlExample {\r
42 \r
43     public static void main(String args[]) throws Exception {\r
44       InputStream input; \r
45         if (args.length > 0) \r
46           input = new FileInputStream(new File(args[0]));\r
47         else \r
48           input = ReadMarcExample.class\r
49                 .getResourceAsStream("resources/brkrtest.mrc");\r
50 \r
51         OutputStream out = System.out;\r
52 \r
53         MarcReader reader = new MarcStreamReader(input);\r
54         MarcWriter writer = new MarcXmlWriter(out, true);\r
55 \r
56         AnselToUnicode converter = new AnselToUnicode();\r
57         writer.setConverter(converter);\r
58 \r
59         while (reader.hasNext()) {\r
60             Record record = reader.next();\r
61             writer.write(record);\r
62         }\r
63         writer.close();\r
64     }\r
65 }\r