Source Code Cross Referenced for BasicIO.java in  » Scripting » FScript » murlen » util » fscript » 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 » FScript » murlen.util.fscript 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package murlen.util.fscript;
002:
003:        import java.io.*;
004:        import java.util.*;
005:
006:        /**
007:         * <p>BasicIO - an simple IO Subclass of FScript</p>
008:         * <p>
009:         * <I>Copyright (C) 2000 murlen.</I></p>
010:         * <p>
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Library General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2 of the License, or (at your option) any later version.</p>
015:         * <p>
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019:         * Library General Public License for more details.</p>
020:         *
021:         * <p>You should have received a copy of the GNU Library General Public
022:         * License along with this library; if not, write to the Free
023:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA </p>
024:         * @author murlen\
025:         *CVSTEST
026:        
027:         */
028:        public class BasicIO extends FScript {
029:
030:            private Object files[];
031:
032:            /**Constructor*/
033:            public BasicIO() {
034:                super ();
035:                files = new Object[25];
036:            }
037:
038:            /**
039:             *<p> Overridden from FScript implements the following FScript functions </p>
040:             *
041:             * <p> note that this only provides very basic IO facilities,
042:             * line by line read/write
043:             * to files, and stdio read write.  There is a maximum of 25 open files</p>
044:             * <p> <b>(void) println(param...)</b> - write to stdout -
045:             * takes variable parameter list </p>
046:             * <p> <b>string readln() </b> - reads a string from stdin </p>
047:             * <p> <b>int open(string filename,string mode) </b> -
048:             * opens a file 'filename' for
049:             * reading (mode="r") or writing (mode="w") returns an integer which is
050:             * used in future calls. Returns -1 on >25 files opened </p>
051:             * <p> <b>string read(fp) </b> - reads one line from previously openened file
052:             * </p>
053:             * <p> <b>void write(fp,param...) - writes concatination of all params to one
054:             * line of file </p>
055:             */
056:            public Object callFunction(String name, ArrayList param)
057:                    throws FSException {
058:
059:                //(void) println(param.....)
060:                if (name.equals("println")) {
061:                    int n;
062:                    String s = "";
063:                    for (n = 0; n < param.size(); n++) {
064:                        s = s + param.get(n);
065:                    }
066:                    System.out.println(s);
067:                }
068:                //string readln()
069:                else if (name.equals("readln")) {
070:                    try {
071:                        return new BufferedReader(new InputStreamReader(
072:                                System.in)).readLine();
073:
074:                    } catch (IOException e) {
075:                        throw new FSException(e.getMessage());
076:                    }
077:                }
078:                //int open(string file,string mode)
079:                else if (name.equals("open")) {
080:                    int n;
081:
082:                    try {
083:                        for (n = 0; n < 25; n++) {
084:                            if (files[n] == null) {
085:                                if (((String) param.get(1)).equals("r")) {
086:                                    files[n] = new BufferedReader(
087:                                            new FileReader((String) param
088:                                                    .get(0)));
089:                                    break;
090:                                } else if (((String) param.get(1)).equals("w")) {
091:                                    files[n] = new BufferedWriter(
092:                                            new FileWriter((String) param
093:                                                    .get(0)));
094:                                    break;
095:                                } else {
096:                                    throw new FSException(
097:                                            "open expects 'r' or 'w' for modes");
098:                                }
099:                            }
100:                        }
101:                    } catch (IOException e) {
102:                        throw new FSException(e.getMessage());
103:                    }
104:                    if (n < 25)
105:                        return new Integer(n);
106:                    else
107:                        return new Integer(-1);
108:                }
109:                //(void)close(int fp)
110:                else if (name.equals("close")) {
111:                    int n;
112:                    n = ((Integer) param.get(0)).intValue();
113:                    if (files[n] == null) {
114:                        throw new FSException(
115:                                "Invalid file number passed to close");
116:                    }
117:                    try {
118:                        if (files[n] instanceof  BufferedWriter) {
119:                            ((BufferedWriter) files[n]).close();
120:                        } else {
121:                            ((BufferedReader) files[n]).close();
122:                        }
123:                        files[n] = null;
124:                    } catch (IOException e) {
125:                        throw new FSException(e.getMessage());
126:                    }
127:                }
128:                //(void) write(params....)
129:                else if (name.equals("write")) {
130:                    int n;
131:                    String s = "";
132:                    for (n = 1; n < param.size(); n++) {
133:                        s = s + param.get(n);
134:                    }
135:                    n = ((Integer) param.get(0)).intValue();
136:                    if (files[n] == null) {
137:                        throw new FSException(
138:                                "Invalid file number passed to write");
139:                    }
140:                    if (!(files[n] instanceof  BufferedWriter)) {
141:                        throw new FSException("Invalid file mode for write");
142:                    }
143:                    try {
144:                        ((BufferedWriter) files[n]).write(s, 0, s.length());
145:                        ((BufferedWriter) files[n]).newLine();
146:                    } catch (IOException e) {
147:                        throw new FSException(e.getMessage());
148:                    }
149:                }
150:                //string read(int fp)
151:                else if (name.equals("read")) {
152:                    int n;
153:                    String s;
154:                    n = ((Integer) param.get(0)).intValue();
155:                    if (files[n] == null) {
156:                        throw new FSException(
157:                                "Invalid file number passed to read");
158:                    }
159:                    if (!(files[n] instanceof  BufferedReader)) {
160:                        throw new FSException("Invalid file mode for read");
161:                    }
162:                    try {
163:                        s = ((BufferedReader) files[n]).readLine();
164:                        //dodge eof problems
165:                        if (s == null)
166:                            s = "";
167:                        return s;
168:                    } catch (IOException e) {
169:                        throw new FSException(e.getMessage());
170:                    }
171:                }
172:                //int eof(fp)
173:                else if (name.equals("eof")) {
174:                    int n;
175:                    n = ((Integer) param.get(0)).intValue();
176:                    if (files[n] == null) {
177:                        throw new FSException(
178:                                "Invalid file number passed to eof");
179:                    }
180:                    BufferedReader br = (BufferedReader) files[n];
181:                    try {
182:                        br.mark(1024);
183:                        if (br.readLine() == null) {
184:                            return new Integer(1);
185:                        } else {
186:                            br.reset();
187:                            return new Integer(0);
188:                        }
189:                    } catch (IOException e) {
190:                        throw new FSException(e.getMessage());
191:                    }
192:                } else {
193:                    super .callFunction(name, param);
194:                }
195:                return new Integer(0);
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.