01: /*
02: * The contents of this file are subject to the terms
03: * of the Common Development and Distribution License
04: * (the "License"). You may not use this file except
05: * in compliance with the License.
06: *
07: * You can obtain a copy of the license at
08: * https://jwsdp.dev.java.net/CDDLv1.0.html
09: * See the License for the specific language governing
10: * permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL
13: * HEADER in each file and include the License file at
14: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
15: * add the following below this CDDL HEADER, with the
16: * fields enclosed by brackets "[]" replaced with your
17: * own identifying information: Portions Copyright [yyyy]
18: * [name of copyright owner]
19: */
20: package com.sun.codemodel.writer;
21:
22: import java.io.FilterOutputStream;
23: import java.io.IOException;
24: import java.io.OutputStream;
25: import java.io.PrintStream;
26:
27: import com.sun.codemodel.CodeWriter;
28: import com.sun.codemodel.JPackage;
29:
30: /**
31: * Output all source files into a single stream with a little
32: * formatting header in front of each file.
33: *
34: * This is primarily for human consumption of the generated source
35: * code, such as to debug/test CodeModel or to quickly inspect the result.
36: *
37: * @author
38: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
39: */
40: public class SingleStreamCodeWriter extends CodeWriter {
41:
42: private final PrintStream out;
43:
44: /**
45: * @param os
46: * This stream will be closed at the end of the code generation.
47: */
48: public SingleStreamCodeWriter(OutputStream os) {
49: out = new PrintStream(os);
50: }
51:
52: public OutputStream openBinary(JPackage pkg, String fileName)
53: throws IOException {
54: String pkgName = pkg.name();
55: if (pkgName.length() != 0)
56: pkgName += '.';
57:
58: out.println("-----------------------------------" + pkgName
59: + fileName + "-----------------------------------");
60:
61: return new FilterOutputStream(out) {
62: public void close() {
63: // don't let this stream close
64: }
65: };
66: }
67:
68: public void close() throws IOException {
69: out.close();
70: }
71:
72: }
|