Source Code Cross Referenced for ReconnectServerStream.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:        // GET http://localhost/1.zip HTTP/1.1
002:        //Host: localhost
003:        //Accept: */*
004:        //Referer: http://localhost
005:        //User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
006:        //Pragma: no-cache
007:        //Cache-Control: no-cache
008:        //Connection: close
009:
010:        //HTTP/1.1 200 OK
011:        //Server: Microsoft-IIS/5.1
012:        //Connection: close
013:        //Date: Sun, 01 Jun 2003 13:28:01 GMT
014:        //Content-Type: application/x-zip-compressed
015:        //Accept-Ranges: bytes
016:        //Last-Modified: Fri, 30 May 2003 05:37:04 GMT
017:        //ETag: "08029806d26c31:847"
018:        //Content-Length: 927645
019:
020:        //GET http://localhost/1.zip HTTP/1.1
021:        //Host: localhost
022:        //Accept: */*
023:        //Referer: http://localhost
024:        //User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
025:        //Range: bytes=268037-
026:        //Pragma: no-cache
027:        //Cache-Control: no-cache
028:        //Connection: close
029:
030:        //HTTP/1.1 206 Partial content
031:        //Server: Microsoft-IIS/5.1
032:        //Connection: close
033:        //Date: Sun, 01 Jun 2003 13:28:56 GMT
034:        //Content-Type: application/x-zip-compressed
035:        //Last-Modified: Fri, 30 May 2003 05:37:04 GMT
036:        //ETag: "08029806d26c31:847"
037:        //Content-Length: 659608
038:        //Content-Range: bytes 268037-927644/927645
039:
040:        package vicazh.hyperpool.stream.net.http;
041:
042:        import java.io.*;
043:        import java.util.*;
044:        import vicazh.hyperpool.stream.*;
045:
046:        class ReconnectServerStream extends ServerStream {
047:            ReconnectServerStream(Session session, OutputStream outputstream) {
048:                super (session, outputstream);
049:            }
050:
051:            public void head(String version, int code, String message)
052:                    throws IOException {
053:                super .head(version, code, message);
054:                if (((ReconnectConnection) session.connection).accept
055:                        && code != PARTIAL_CONTENT) {
056:                    ((ReconnectConnection) session.connection).accept = false;
057:                    throw new BreakException();
058:                }
059:            }
060:
061:            private boolean b;
062:
063:            public void field(String s1, String s2) throws IOException {
064:                super .field(s1, s2);
065:                if (((ReconnectConnection) session.connection).accept)
066:                    return;
067:                if (s1.equalsIgnoreCase("Accept-Ranges")
068:                        && s2.startsWith("bytes"))
069:                    b = true;
070:                else if (s1.equalsIgnoreCase("Content-Range")
071:                        && s2.startsWith("bytes")) {
072:                    StringTokenizer st = new StringTokenizer(s2);
073:                    st.nextToken();
074:                    ((ReconnectConnection) session.connection).index = Long
075:                            .parseLong(st.nextToken("-").trim());
076:                    b = true;
077:                } else if (s1.equalsIgnoreCase("Content-Length"))
078:                    ((ReconnectConnection) session.connection).length = Long
079:                            .parseLong(s2.trim());
080:            }
081:
082:            private Timer timer;
083:
084:            public void header() throws IOException {
085:                super .header();
086:                outputstream = ((ReconnectConnection) connection).serverout;
087:                if (session.getClient().getMethod() != null
088:                        && session.getClient().getMethod().equalsIgnoreCase(
089:                                "get")
090:                        && b
091:                        && (((ReconnectConnection) session.connection).length > 0
092:                                || getCode() == OK || getCode() == PARTIAL_CONTENT)) {
093:                    ((ReconnectConnection) connection).length += ((ReconnectConnection) connection).index;
094:                    ((ReconnectConnection) connection).accept = true;
095:                }
096:                if (!((ReconnectConnection) connection).accept)
097:                    return;
098:                timer = new Timer();
099:                timer.schedule(new TimerTask() {
100:                    private long indexsave;
101:
102:                    private long time;
103:
104:                    public void run() {
105:                        if (((ReconnectConnection) connection).index == indexsave) {
106:                            if (new Date().getTime() - time < ((ReconnectService) connection.element)
107:                                    .getTimeout() * 1000)
108:                                return;
109:                            timer.cancel();
110:                            try {
111:                                ((ReconnectConnection) connection).clientout
112:                                        .flush();
113:                            } catch (Exception e) {
114:                            }
115:                            try {
116:                                ((ReconnectConnection) connection).clientout
117:                                        .close();
118:                            } catch (Exception e) {
119:                            }
120:                        } else {
121:                            indexsave = ((ReconnectConnection) connection).index;
122:                            time = new Date().getTime();
123:                        }
124:                    }
125:                }, 1000, 1000);
126:            }
127:
128:            public void content(int i) throws IOException {
129:                ((ReconnectConnection) session.connection).index++;
130:                super .content(i);
131:            }
132:
133:            public void end() {
134:                if (timer != null)
135:                    timer.cancel();
136:                super .end();
137:            }
138:
139:            public void close() throws IOException {
140:                if (timer != null)
141:                    timer.cancel();
142:                if (((ReconnectConnection) session.connection).check(session))
143:                    super.close();
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.