Source Code Cross Referenced for StdChannel.java in  » Scripting » jacl » tcl » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » jacl » tcl.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * StdChannel.java --
003:         *
004:         * Copyright (c) 1997 Sun Microsystems, Inc.
005:         *
006:         * See the file "license.terms" for information on usage and
007:         * redistribution of this file, and for a DISCLAIMER OF ALL
008:         * WARRANTIES.
009:         * 
010:         * RCS: @(#) $Id: StdChannel.java,v 1.19 2003/03/08 03:42:44 mdejong Exp $
011:         *
012:         */
013:
014:        package tcl.lang;
015:
016:        import java.util.*;
017:        import java.io.*;
018:
019:        /**
020:         * Subclass of the abstract class Channel.  It implements all of the 
021:         * methods to perform read, write, open, close, etc on system stdio channels.
022:         */
023:
024:        class StdChannel extends Channel {
025:
026:            /**
027:             * stdType store which type, of the three below, this StdChannel is.
028:             */
029:
030:            private int stdType = -1;
031:
032:            /**
033:             * Flags indicating the type of this StdChannel.
034:             */
035:
036:            static final int STDIN = 0;
037:            static final int STDOUT = 1;
038:            static final int STDERR = 2;
039:
040:            /**
041:             * Constructor that does nothing.  Open() must be called before
042:             * any of the subsequent read, write, etc calls can be made.
043:             */
044:
045:            StdChannel() {
046:            }
047:
048:            /**
049:             * Constructor that will automatically call open.
050:             *
051:             * @param stdName name of the stdio channel; stdin, stderr or stdout.
052:             */
053:
054:            StdChannel(String stdName) {
055:                if (stdName.equals("stdin")) {
056:                    open(STDIN);
057:                } else if (stdName.equals("stdout")) {
058:                    open(STDOUT);
059:                } else if (stdName.equals("stderr")) {
060:                    open(STDERR);
061:                } else {
062:                    throw new TclRuntimeError(
063:                            "Error: unexpected type for StdChannel");
064:                }
065:            }
066:
067:            StdChannel(int type) {
068:                open(type);
069:            }
070:
071:            /**
072:             * Set the channel type to one of the three stdio types.  Throw a 
073:             * tclRuntimeEerror if the stdName is not one of the three types.  If
074:             * it is a stdin channel, initialize the "in" data member.  Since "in"
075:             * is static it may have already be initialized, test for this case 
076:             * first.  Set the names to fileX, this will be the key in the chanTable 
077:             * hashtable to access this object.  Note: it is not put into the hash 
078:             * table in this function.  The calling function is responsible for that.
079:             *
080:             * @param stdName String that equals stdin, stdout, stderr
081:             * @return The name of the channelId
082:             */
083:
084:            String open(int type) {
085:
086:                switch (type) {
087:                case STDIN:
088:                    mode = TclIO.RDONLY;
089:                    setBuffering(TclIO.BUFF_LINE);
090:                    setChanName("stdin");
091:                    break;
092:                case STDOUT:
093:                    mode = TclIO.WRONLY;
094:                    setBuffering(TclIO.BUFF_LINE);
095:                    setChanName("stdout");
096:                    break;
097:                case STDERR:
098:                    mode = TclIO.WRONLY;
099:                    setBuffering(TclIO.BUFF_NONE);
100:                    setChanName("stderr");
101:                    break;
102:                default:
103:                    throw new RuntimeException(
104:                            "type does not match one of STDIN, STDOUT, or STDERR");
105:                }
106:
107:                stdType = type;
108:
109:                return getChanName();
110:            }
111:
112:            /**
113:             * Write to stdout or stderr.  If the stdType is not set to 
114:             * STDOUT or STDERR this is an error; either the stdType wasnt
115:             * correctly initialized, or this was called on a STDIN channel.
116:             *
117:             * @param interp the current interpreter.
118:             * @param s the string to write 
119:             */
120:
121:            void write(Interp interp, TclObject outData) throws IOException,
122:                    TclException {
123:
124:                checkWrite(interp);
125:
126:                if (stdType == STDERR) {
127:                    System.err.print(outData.toString());
128:                } else {
129:                    String s = outData.toString();
130:                    System.out.print(s);
131:                    if (buffering == TclIO.BUFF_NONE
132:                            || (buffering == TclIO.BUFF_LINE && s
133:                                    .endsWith("\n"))) {
134:                        System.out.flush();
135:                    }
136:                }
137:            }
138:
139:            /**
140:             * Check for any output that might still need to be flushed
141:             * when the channel is closed.
142:             */
143:
144:            void close() throws IOException {
145:                super .close();
146:
147:                if (stdType == STDOUT)
148:                    System.out.flush();
149:            }
150:
151:            String getChanType() {
152:                return "tty";
153:            }
154:
155:            protected InputStream getInputStream() throws IOException {
156:                return System.in;
157:            }
158:
159:            protected OutputStream getOutputStream() throws IOException {
160:                throw new RuntimeException("should never be called");
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.