Source Code Cross Referenced for SysInPort.java in  » Scripting » Nice » gnu » mapping » 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 » Nice » gnu.mapping 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        package gnu.mapping;
02:
03:        import java.io.*;
04:
05:        /** A class to compensate from System.in blocking other threads. */
06:
07:        public class SysInPort extends TtyInPort {
08:            InputStream inStream;
09:
10:            public SysInPort(InputStream inStream, String name, OutPort tie) {
11:                super (inStream, name, tie);
12:                this .inStream = inStream;
13:            }
14:
15:            public int fill(int len) throws java.io.IOException {
16:                int off = pos;
17:                /* This explanation and work-around comes from jacl 1.0's Shell.java:
18:                 *
19:                 * On Unix platforms, System.in.read() will block the delivery of
20:                 * of AWT events. We must make sure System.in.available() is larger
21:                 * than zero before attempting to read from System.in. Since
22:                 * there is no asynchronous IO in Java, we must poll the System.in
23:                 * every 100 milliseconds.
24:                 */
25:
26:                if (!in.ready()) {
27:                    try {
28:                        while (inStream.available() == 0)
29:                            Thread.currentThread().sleep(100);
30:                    } catch (java.lang.InterruptedException ex) {
31:                    } catch (java.io.IOException ex) {
32:                        // available or ready does not seem to be supported or working.
33:                    }
34:                }
35:
36:                // It would be more efficient to just do super.fill(buffer, off, len).
37:                // Unfortunately, that may hang.  One reported problem is when running
38:                // Kawa inside a shell or inferior-lisp window in ntemacs on Windows NT.
39:                // Ntemacs uses pipes to communicate with the inferior shell (because
40:                // pseudo-ttys are not available).  This causes too much input to be
41:                // buffered.  (The problem seems to be in java.io.InputStreamReader.)
42:
43:                int count;
44:                for (count = 0; count < len;) {
45:                    int ch = in.read();
46:                    if (ch < 0) {
47:                        if (count == 0)
48:                            return -1;
49:                        break;
50:                    }
51:                    buffer[off++] = (char) (0xff & ch);
52:                    count++;
53:                    if (ch == '\n' || ch == '\r')
54:                        break;
55:                }
56:                if (tie != null)
57:                    tie.echo(buffer, off - count, count);
58:                return count;
59:            }
60:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.