KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > io > ClassFileWriter


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.io;
9
10 import org.gjt.jclasslib.structures.ClassFile;
11 import org.gjt.jclasslib.structures.InvalidByteCodeException;
12
13 import java.io.*;
14
15 /**
16     Converts class file structure <tt>ClassFile</tt> as defined in
17     <tt>org.gjt.jclasslib.structures</tt> to class files.
18  
19     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
20     @version $Revision: 1.4 $ $Date: 2003/08/18 07:58:12 $
21 */

22 public class ClassFileWriter {
23
24     private ClassFileWriter() {
25     }
26
27     /**
28         Converts <tt>ClassFile</tt> structure to a a class file.
29         @param file the file to which to write the <tt>ClassFile</tt> structure
30         @param classFile the <tt>ClassFile</tt> structure to be written
31         @throws InvalidByteCodeException if the code is invalid
32         @throws IOException if an exception occurs while reading the file
33      */

34     public static void writeToFile(File file, ClassFile classFile)
35         throws InvalidByteCodeException, IOException {
36             
37         DataOutputStream out = new DataOutputStream(
38                                 new BufferedOutputStream(
39                                 new FileOutputStream(file)));
40         
41         classFile.write(out);
42         out.flush();
43         out.close();
44     }
45     
46 }
47
Popular Tags