Source Code Cross Referenced for ThreadLocalInputStream.java in  » Net » NailGun » com » martiansoftware » nailgun » 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 » Net » NailGun » com.martiansoftware.nailgun 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   
002:
003:          Copyright 2004, Martian Software, Inc.
004:
005:          Licensed under the Apache License, Version 2.0 (the "License");
006:          you may not use this file except in compliance with the License.
007:          You may obtain a copy of the License at
008:
009:          http://www.apache.org/licenses/LICENSE-2.0
010:
011:          Unless required by applicable law or agreed to in writing, software
012:          distributed under the License is distributed on an "AS IS" BASIS,
013:          WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:          See the License for the specific language governing permissions and
015:          limitations under the License.
016:
017:         */
018:
019:        package com.martiansoftware.nailgun;
020:
021:        import java.io.IOException;
022:        import java.io.InputStream;
023:
024:        /**
025:         * The class name is pretty descriptive.  This creates an InputStream
026:         * much like a FilterInputStream, but with the wrapped InputStream
027:         * being local to the current Thread.  By setting System.in to a
028:         * ThreadLocalInputStream, different Threads can read from different
029:         * InputStreams simply by using System.in.  Of course, the init()
030:         * method must be called by the Thread that wishes to use the 
031:         * wrapped stream.
032:         *  
033:         * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
034:         */
035:        class ThreadLocalInputStream extends InputStream {
036:
037:            /**
038:             * The InputStreams for the various threads
039:             */
040:            private InheritableThreadLocal streams = null;
041:
042:            private InputStream defaultInputStream = null;
043:
044:            /**
045:             * @param defaultInputStream the InputStream that will be used if the
046:             * current thread has not called init()
047:             */
048:            ThreadLocalInputStream(InputStream defaultInputStream) {
049:                super ();
050:                streams = new InheritableThreadLocal();
051:                this .defaultInputStream = defaultInputStream;
052:                init(null);
053:            }
054:
055:            /**
056:             * Sets the InputStream for the current thread
057:             * @param streamForCurrentThread the InputStream for the current thread
058:             */
059:            void init(InputStream streamForCurrentThread) {
060:                streams.set(streamForCurrentThread);
061:            }
062:
063:            /**
064:             * Returns this thread's InputStream
065:             * @return this thread's InputStream
066:             */
067:            InputStream getInputStream() {
068:                InputStream result = (InputStream) streams.get();
069:                return ((result == null) ? defaultInputStream : result);
070:            }
071:
072:            //  BEGIN delegated java.io.InputStream methods
073:
074:            /**
075:             * @see java.io.InputStream#available()
076:             */
077:            public int available() throws IOException {
078:                return (getInputStream().available());
079:            }
080:
081:            /**
082:             * @see java.io.InputStream#close()
083:             */
084:            public void close() throws IOException {
085:                getInputStream().close();
086:            }
087:
088:            /**
089:             * @see java.io.InputStream#mark(int)
090:             */
091:            public void mark(int readlimit) {
092:                getInputStream().mark(readlimit);
093:            }
094:
095:            /**
096:             * @see java.io.InputStream#markSupported()
097:             */
098:            public boolean markSupported() {
099:                return (getInputStream().markSupported());
100:            }
101:
102:            /**
103:             * @see java.io.InputStream#read()
104:             */
105:            public int read() throws IOException {
106:                return (getInputStream().read());
107:            }
108:
109:            /**
110:             * @see java.io.InputStream#read(byte[])
111:             */
112:            public int read(byte[] b) throws IOException {
113:                return (getInputStream().read(b));
114:            }
115:
116:            /**
117:             * @see java.io.InputStream#read(byte[],int,int)
118:             */
119:            public int read(byte[] b, int off, int len) throws IOException {
120:                return (getInputStream().read(b, off, len));
121:            }
122:
123:            /**
124:             * @see java.io.InputStream#reset()
125:             */
126:            public void reset() throws IOException {
127:                getInputStream().reset();
128:            }
129:
130:            /**
131:             * @see java.io.InputStream#skip(long)
132:             */
133:            public long skip(long n) throws IOException {
134:                return (getInputStream().skip(n));
135:            }
136:
137:            //  BEGIN delegated java.io.InputStream methods
138:
139:            //  Note: Should java.lang.Object methods be delegated? If not, and
140:            //  someone synchronizes on this stream, processes might be blocked
141:            //  that shouldn't be.  It would certainly be stupid to delegate
142:            //  finalize().  Not so clear are hashcode(), equals(), notify(), and
143:            //  the wait() methods.
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.