View Javadoc
1   /*
2    * Copyright 2012 Olivier Godineau
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at http://www.apache.org/licenses/LICENSE-2.0
7    * 
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11   * License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package olg.csv.bean;
15  
16  import java.io.File;
17  import java.io.FileNotFoundException;
18  import java.io.FileOutputStream;
19  import java.io.IOException;
20  import java.io.InputStream;
21  
22  /**
23   * Provides main method to extraxt XSD schema from jar.
24   * 
25   * @author Olivier Godineau
26   * 
27   */
28  public final class SchemaMain {
29  
30  	/**
31  	 * Namespace to use within your XML Declaration.
32  	 */
33  	public static final String BASE_NAMESPACE_MAPPING = "http://www.example.org/row-bean";
34  
35  	/**
36  	 * private constructor to prevent its instantiation.
37  	 */
38  	private SchemaMain() {
39  
40  	}
41  
42  	/**
43  	 * Allows to write in a file named bean-row.xsd the xsd schema used to
44  	 * create reader or writer configuration.
45  	 * 
46  	 * @param args
47  	 *            unused
48  	 */
49  	public static void main(String[] args) {
50  		System.out.println("Copy of bean-row.xsd ..."); // NOPMD by olivier on
51  														// 05/01/12 01:02
52  
53  		File destination = new File("bean-row.xsd");
54  
55  		InputStream input = null;
56  		java.io.FileOutputStream destinationFile = null;
57  		try {
58  
59  			input = Util.class.getResourceAsStream("bean-row.xsd");
60  			destinationFile = new FileOutputStream(destination);
61  
62  			byte[] buffer = new byte[512 * 1024];
63  			int nbLecture;
64  
65  			while ((nbLecture = input.read(buffer)) != -1) { // NOPMD by olivier
66  																// on 28/01/12
67  																// 14:17
68  				destinationFile.write(buffer, 0, nbLecture);
69  			}
70  
71  			System.out.println("Done"); // NOPMD by olivier on 05/01/12 01:02
72  			System.out.println("See your copy " + destination.getAbsolutePath()); // NOPMD
73  																					// by
74  																					// olivier
75  																					// on
76  																					// 05/01/12
77  																					// 01:02
78  			System.out.println("Don't forget to declare the following namespace in your XML Declaration :"
79  					+ BASE_NAMESPACE_MAPPING); // NOPMD by olivier on 05/01/12
80  												// 01:02
81  		} catch (FileNotFoundException e) {
82  
83  			e.printStackTrace(); // NOPMD by olivier on 05/01/12 01:03
84  		} catch (IOException e) {
85  
86  			e.printStackTrace(); // NOPMD by olivier on 05/01/12 01:03
87  		} finally {
88  			if (destinationFile != null) {
89  				try {
90  					destinationFile.close();
91  				} catch (IOException ex) {
92  					ex.printStackTrace(); // NOPMD by olivier on 28/01/12 14:13
93  				}
94  			}
95  
96  			if (input != null) {
97  				try {
98  					input.close();
99  				} catch (IOException ex) {
100 					ex.printStackTrace(); // NOPMD by olivier on 28/01/12 14:13
101 				}
102 			}
103 
104 		}
105 
106 	}
107 }