Source Code Cross Referenced for HttpConnection.java in  » Web-Crawler » JoBo » net » matuschek » http » connection » 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 » Web Crawler » JoBo » net.matuschek.http.connection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.matuschek.http.connection;
002:
003:        import java.io.IOException;
004:        import java.io.InputStream;
005:        import java.io.InterruptedIOException;
006:        import java.io.OutputStream;
007:        import java.net.InetAddress;
008:        import java.net.Socket;
009:        import net.matuschek.util.TimedSocket;
010:
011:        /*********************************************
012:         Copyright (c) 2001 by Daniel Matuschek
013:         *********************************************/
014:
015:        /**
016:         * An HttpConnection object simply represents a TCP socket connection
017:         * between the client and an HTTP server.
018:         * 
019:         * @author Daniel Matuschek 
020:         * @version $Id: HttpConnection.java,v 1.4 2002/05/31 14:45:55 matuschd Exp $
021:         */
022:        public class HttpConnection {
023:
024:            /** the TCP socket to use */
025:            private Socket socket = null;
026:
027:            /**
028:             * Create a new HttpConnection to the given host and port.
029:             *
030:             * @param address the IP address to connect to
031:             * @param port the port to connect to (usually 80 for HTTP)
032:             * @param timeout connection timeout in milliseconds. If the connection
033:             * could not be established after this time, an exception will
034:             * be thrown. This timeout will also be set as timeout for the
035:             * TCP connection (so timeout)
036:             * An timeout of 0 will be interpreted as an infinite timeout.
037:             * @return a new HttpConnection object
038:             * @exception IOException if the TCP socket connection could
039:             * not be established
040:             */
041:            public static HttpConnection createConnection(InetAddress address,
042:                    int port, int timeout) throws IOException {
043:                HttpConnection connection = new HttpConnection();
044:                try {
045:                    connection.socket = TimedSocket.getSocket(address, port,
046:                            timeout);
047:                    connection.socket.setSoTimeout(timeout);
048:                } catch (InterruptedIOException e) {
049:                    throw new IOException("timeout during connect: "
050:                            + e.getMessage());
051:                }
052:                return connection;
053:            }
054:
055:            /**
056:             * Gets the InputStream of this connection. Don't close this stream,
057:             * but close the HttpConnection when finished.
058:             *
059:             * @return an InputStream or null if no connection is established
060:             * @exception IOException if an I/O error occurs when creating the stream
061:             */
062:            public InputStream getInputStream() throws IOException {
063:                if (socket == null)
064:                    throw new IOException("not conected");
065:                return socket.getInputStream();
066:            }
067:
068:            /**
069:             * Gets the OutputStream of this connection. Don't close this stream,
070:             * but close the HttpConnection when finished.
071:             *
072:             * @return an OutputStream or null if no connection is established
073:             * @exception IOException if an I/O error occurs when creating the stream
074:             */
075:            public OutputStream getOutputStream() throws IOException {
076:                if (socket == null)
077:                    throw new IOException("not conected");
078:                return socket.getOutputStream();
079:            }
080:
081:            /** 
082:             * Close this connection (including the streams)
083:             */
084:            public void close() {
085:                try {
086:                    socket.close();
087:                } catch (IOException e) {
088:                    // do not throw an I/O error on close
089:                }
090:            }
091:
092:            /**
093:             * Create a new HttpConnection
094:             */
095:            protected HttpConnection() {
096:            }
097:
098:            /**
099:             * Construct an HTTP connection object based on an existing socket
100:             * connection.
101:             *
102:             * @param socket a Socket object containing a socket connection 
103:             * that is already established.
104:             */
105:            public HttpConnection(Socket socket) {
106:                this.socket = socket;
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.