01: /*
02: * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25: /*
26: * COMPONENT_NAME: idl.parser
27: *
28: * ORIGINS: 27
29: *
30: * Licensed Materials - Property of IBM
31: * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
32: * RMI-IIOP v1.0
33: *
34: * @(#)GenFileStream.java 1.20 07/05/05
35: */
36:
37: package com.sun.tools.corba.se.idl;
38:
39: // NOTES:
40:
41: import java.io.CharArrayWriter;
42: import java.io.File;
43: import java.io.FileWriter;
44: import java.io.IOException;
45: import java.io.PrintWriter;
46:
47: public class GenFileStream extends PrintWriter {
48: public GenFileStream(String filename) {
49: // What I really want to do here is:
50: // super (byteStream = new ByteArrayOutputStream ());
51: // but that isn't legal. The super constructor MUST
52: // be called before any instance variables are used.
53: // This implementation gets around that problem.
54: // <f49747.1>
55: //super (tmpByteStream = new ByteArrayOutputStream ());
56: //byteStream = tmpByteStream;
57: super (tmpCharArrayWriter = new CharArrayWriter());
58: charArrayWriter = tmpCharArrayWriter;
59: name = filename;
60: } // ctor
61:
62: public void close() {
63: File file = new File(name);
64: try {
65: if (checkError())
66: throw new IOException();
67: // <f49747.1>
68: //FileOutputStream fileStream = new FileOutputStream (file);
69: //fileStream.write (byteStream.toByteArray ());
70: //fileStream.close ();
71: FileWriter fileWriter = new FileWriter(file);
72: fileWriter.write(charArrayWriter.toCharArray());
73: fileWriter.close();
74: } catch (IOException e) {
75: String[] parameters = { name, e.toString() };
76: System.err.println(Util.getMessage("GenFileStream.1",
77: parameters));
78: }
79: super .close();
80: } // close
81:
82: public String name() {
83: return name;
84: } // name
85:
86: // <f49747.1>
87: //private ByteArrayOutputStream byteStream;
88: //private static ByteArrayOutputStream tmpByteStream;
89: private CharArrayWriter charArrayWriter;
90: private static CharArrayWriter tmpCharArrayWriter;
91: private String name;
92: } // GenFileStream
|