Source Code Cross Referenced for ServerStream.java in  » Net » hyperpool-0.4.0 » vicazh » hyperpool » stream » net » http » 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 » hyperpool 0.4.0 » vicazh.hyperpool.stream.net.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package vicazh.hyperpool.stream.net.http;
002:
003:        import java.io.*;
004:        import java.util.*;
005:
006:        /**
007:         * This class implements an http stream from server
008:         * 
009:         * @author Victor Zhigunov
010:         * @version 0.4.0
011:         */
012:        public class ServerStream extends Stream {
013:
014:            public static final int ACCEPTED = 202;
015:
016:            public static final int BAD_GATEWAY = 502;
017:
018:            public static final int BAD_REQUEST = 400;
019:
020:            public static final int CONFLICT = 409;
021:
022:            public static final int CONTINUE = 100;
023:
024:            public static final int CREATED = 201;
025:
026:            public static final int EXPECTATION_FAILED = 417;
027:
028:            public static final int FORBIDDEN = 403;
029:
030:            public static final int FOUND = 302;
031:
032:            public static final int GATEWAY_TIMEOUT = 504;
033:
034:            public static final int GONE = 410;
035:
036:            public static final int HTTP_VERSION_NOT_SUPPORTED = 505;
037:
038:            public static final int INTERNAL_SERVER_ERROR = 500;
039:
040:            public static final int LENGTH_REQUIRED = 411;
041:
042:            public static final int METHOD_NOT_ALLOWED = 405;
043:
044:            public static final int MOVED_PERMANENTLY = 301;
045:
046:            public static final int MOVED_TEMPORARILY = 302;
047:
048:            public static final int MULTIPLE_CHOICES = 300;
049:
050:            public static final int NO_CONTENT = 204;
051:
052:            public static final int NON_AUTHORITATIVE_INFORMATION = 203;
053:
054:            public static final int NOT_ACCEPTABLE = 406;
055:
056:            public static final int NOT_FOUND = 404;
057:
058:            public static final int NOT_IMPLEMENTED = 501;
059:
060:            public static final int NOT_MODIFIED = 304;
061:
062:            public static final int OK = 200;
063:
064:            public static final int PARTIAL_CONTENT = 206;
065:
066:            public static final int PAYMENT_REQUIRED = 402;
067:
068:            public static final int PRECONDITION_FAILED = 412;
069:
070:            public static final int PROXY_AUTHENTICATION_REQUIRED = 407;
071:
072:            public static final int REQUEST_ENTITY_TOO_LARGE = 413;
073:
074:            public static final int REQUEST_TIMEOUT = 408;
075:
076:            public static final int REQUEST_URI_TOO_LONG = 414;
077:
078:            public static final int REQUESTED_RANGE_NOT_SATISFIABLE = 416;
079:
080:            public static final int RESET_CONTENT = 205;
081:
082:            public static final int SEE_OTHER = 303;
083:
084:            public static final int SERVICE_UNAVAILABLE = 503;
085:
086:            public static final int SWITCHING_PROTOCOLS = 101;
087:
088:            public static final int TEMPORARY_REDIRECT = 307;
089:
090:            public static final int UNAUTHORIZED = 401;
091:
092:            public static final int UNSUPPORTED_MEDIA_TYPE = 415;
093:
094:            public static final int USE_PROXY = 305;
095:
096:            public ServerStream() {
097:            }
098:
099:            private static final char SP = ' ';
100:
101:            private String version;
102:
103:            /**
104:             * Set the version
105:             */
106:            public void setVersion(String version) {
107:                this .version = version;
108:            }
109:
110:            /**
111:             * Get the version
112:             */
113:            public String getVersion() {
114:                return version;
115:            }
116:
117:            private int code;
118:
119:            /**
120:             * Set the code
121:             */
122:            public void setCode(int code) {
123:                this .code = code;
124:            }
125:
126:            /**
127:             * Get the code
128:             */
129:            public int getCode() {
130:                return code;
131:            }
132:
133:            private String message;
134:
135:            /**
136:             * Set the message
137:             */
138:            public void setMessage(String message) {
139:                this .message = message;
140:            }
141:
142:            /**
143:             * Get the message
144:             */
145:            public String getMessage() {
146:                return message;
147:            }
148:
149:            /**
150:             * @param session
151:             *            parent session
152:             * @param outputstream
153:             *            linked output stream
154:             */
155:            public ServerStream(Session session, OutputStream outputstream) {
156:                super (session, outputstream);
157:            }
158:
159:            private final static String START = "HTTP/";
160:
161:            public void write(int b) throws IOException {
162:                super .write(b);
163:                if (mode != HEAD || stream.size() != START.length())
164:                    return;
165:                byte[] a = stream.toByteArray();
166:                if (new String(a).equalsIgnoreCase(START))
167:                    return;
168:                head("HTTP/1.0", OK, "");
169:                header();
170:                for (int i = 0; i < a.length; i++)
171:                    content(a[i]);
172:            }
173:
174:            public void head(String s) throws IOException {
175:                StringTokenizer stringtokenizer = new StringTokenizer(s);
176:                version = stringtokenizer.nextToken();
177:                code = Integer.parseInt(stringtokenizer.nextToken());
178:                if (stringtokenizer.hasMoreTokens())
179:                    message = stringtokenizer.nextToken();
180:                else
181:                    message = "";
182:                while (stringtokenizer.hasMoreTokens())
183:                    message += SP + stringtokenizer.nextToken();
184:                head(version, code, message);
185:            }
186:
187:            /**
188:             * Writes the http parameters to this stream
189:             * 
190:             * @param version
191:             *            the http version
192:             * @param code
193:             *            the http return code
194:             * @param message
195:             *            the http return message
196:             */
197:            public void head(String version, int code, String message)
198:                    throws IOException {
199:                this .version = version;
200:                this .code = code;
201:                this .message = message;
202:                super .head(version + SP + String.valueOf(code) + SP + message);
203:            }
204:
205:            public void header() throws IOException {
206:                super .header();
207:                if (code == CONTINUE)
208:                    mode = HEAD;
209:            }
210:
211:            protected boolean isContent() {
212:                return code == CONTINUE
213:                        || ((code == OK || getFields().containsKey(
214:                                "content-type"))
215:                                && length == -1
216:                                || code == PARTIAL_CONTENT
217:                                || length > 0
218:                                || version.equalsIgnoreCase("http/1.0") || isChunked)
219:                        && (session.getClient().getMethod() == null || !session
220:                                .getClient().getMethod().equalsIgnoreCase(
221:                                        "head"));
222:            }
223:
224:            public void end() {
225:                super .end();
226:                session.close();
227:            }
228:
229:            protected void set() throws IOException {
230:                synchronized (session) {
231:                    if (((Connection) connection).getSessions().size() == 0)
232:                        try {
233:                            session.wait();
234:                        } catch (InterruptedException e) {
235:                        }
236:                }
237:                Session s = ((Connection) connection).getSessions().get(0);
238:                s.setServer(outputstream);
239:                connection.getServer().outputstream = s.getServer();
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.