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


001:        package vicazh.hyperpool.stream.net.socks;
002:
003:        import java.io.*;
004:        import vicazh.hyperpool.stream.Connection;
005:
006:        /**
007:         * This class is the superclass of all socks stream data
008:         * 
009:         * @author Victor Zhigunov
010:         * @version 0.3.14
011:         */
012:        public class Stream extends vicazh.hyperpool.stream.net.Stream {
013:            public Stream() {
014:            }
015:
016:            /**
017:             * @param connection
018:             *            parent connection
019:             * @param outputstream
020:             *            linked output stream
021:             */
022:            public Stream(Connection connection, OutputStream outputstream) {
023:                super (connection, outputstream);
024:            }
025:
026:            private int type;
027:
028:            /**
029:             * Set the type
030:             */
031:            public void setType(int type) {
032:                this .type = type;
033:            }
034:
035:            /**
036:             * Get the type
037:             */
038:            public int getType() {
039:                return type;
040:            }
041:
042:            private byte[] address;
043:
044:            /**
045:             * Set the address
046:             */
047:            public void setAddress(byte[] address) {
048:                this .address = address;
049:            }
050:
051:            /**
052:             * Get the address
053:             */
054:            public byte[] getAddress() {
055:                return address;
056:            }
057:
058:            private int command;
059:
060:            /**
061:             * Set the command
062:             */
063:            public void setCommand(int command) {
064:                this .command = command;
065:            }
066:
067:            /**
068:             * Get the command
069:             */
070:            public int getCommand() {
071:                return command;
072:            }
073:
074:            private int port;
075:
076:            /**
077:             * Set the port
078:             */
079:            public void setPort(int port) {
080:                this .port = port;
081:            }
082:
083:            /**
084:             * Get the port
085:             */
086:            public int getPort() {
087:                return port;
088:            }
089:
090:            protected enum Mode {
091:                AUTH, HEAD, CONTENT
092:            };
093:
094:            protected Mode mode = Mode.AUTH;
095:
096:            private int index;
097:
098:            public void write(int b) throws IOException {
099:                if (mode == Mode.CONTENT)
100:                    content(b);
101:                else {
102:                    if (index == 1)
103:                        command = b;
104:                    else if (index == 3)
105:                        type = b;
106:                    else
107:                        switch (type) {
108:                        case 1:
109:                            if (index == 4)
110:                                address = new byte[4];
111:                            if (index <= address.length + 3)
112:                                address[index - 4] = (byte) b;
113:                            else if (index == address.length + 4)
114:                                port = b;
115:                            else
116:                                head(command, type, address, (port << 8) + b);
117:                            break;
118:                        case 3:
119:                            if (index == 4)
120:                                address = new byte[b];
121:                            else if (index <= address.length + 4)
122:                                address[index - 5] = (byte) b;
123:                            else if (index == address.length + 5)
124:                                port = b;
125:                            else
126:                                head(command, type, address, (port << 8) + b);
127:                            break;
128:                        case 4:
129:                            if (index == 4)
130:                                address = new byte[6];
131:                            if (index <= address.length + 3)
132:                                address[index - 4] = (byte) b;
133:                            else if (index == address.length + 4)
134:                                port = b;
135:                            else
136:                                head(command, type, address, (port << 8) + b);
137:                            break;
138:                        }
139:                    index++;
140:                }
141:            }
142:
143:            /**
144:             * Writes the socks authentication data to this stream
145:             * 
146:             * @param data
147:             *            the data
148:             */
149:            public void auth(byte[] data) throws IOException {
150:                super .write(5);
151:                for (byte b : data)
152:                    super .write(b);
153:                mode = Mode.HEAD;
154:            }
155:
156:            /**
157:             * Writes the socks parameters to this stream
158:             * 
159:             * @param command
160:             *            the socks command
161:             * @param type
162:             *            the address type
163:             * @param address
164:             *            the address
165:             * @param port
166:             *            the port
167:             */
168:            public void head(int command, int type, byte[] address, int port)
169:                    throws IOException {
170:                this .command = command;
171:                this .type = type;
172:                this .address = address;
173:                this .port = port;
174:                super .write(5);
175:                super .write(command);
176:                super .write(0);
177:                super .write(type);
178:                if (type == 3)
179:                    super .write(address.length);
180:                for (byte b : address)
181:                    super .write(b);
182:                super .write(port >> 8);
183:                super .write((byte) port);
184:                mode = Mode.CONTENT;
185:            }
186:
187:            /**
188:             * Writes the content to this stream
189:             * 
190:             * @param b
191:             *            the <code>byte</code>
192:             */
193:            public void content(int b) throws IOException {
194:                super.write(b);
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.