Source Code Cross Referenced for PostConnection.java in  » Portal » Open-Portal » communications » 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 » Portal » Open Portal » communications 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *	CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003:         *	NETSCAPE COMMUNICATIONS CORPORATION
004:         *
005:         *	Copyright (c) 1996 Netscape Communications Corporation.
006:         *	All Rights Reserved.
007:         *	Use of this Source Code is subject to the terms of the applicable
008:         *	license agreement from Netscape Communications Corporation.
009:         */
010:
011:        package communications;
012:
013:        import util.ReportError;
014:
015:        import java.io.DataOutputStream;
016:        import java.io.OutputStream;
017:        import java.io.DataInputStream;
018:        import java.io.IOException;
019:
020:        /**
021:         * Wraps up managing a "post" style connection.
022:         * <p>
023:         * Note that the internal URLConnection,
024:         * contrary to the URLConnection default, is
025:         * <i>setDoOutput(true)</i>.
026:         */
027:        public class PostConnection extends ReadConnection {
028:            /**
029:             * The output stream.
030:             */
031:            protected OutputStream os;
032:
033:            /**
034:             * The data output stream.
035:             */
036:            protected DataOutputStream dos;
037:
038:            /**
039:             * Whether the current stream is valid.
040:             */
041:            protected boolean validOut;
042:
043:            /**
044:             * Constructs a PostConnection.
045:             * @param s the URL
046:             */
047:            public PostConnection(String s) {
048:                super (s);
049:                os = null;
050:                dos = null;
051:                validOut = false;
052:            }
053:
054:            /**
055:             * Sets the URL.
056:             * @param s the URL
057:             */
058:            public void setURL(String s) {
059:                super .setURL(s);
060:                validOut = false;
061:            }
062:
063:            /**
064:             * Opens the connection.
065:             */
066:            protected boolean openCon() {
067:                if (validCon)
068:                    return true;
069:                boolean b = super .openCon();
070:                urlc.setDoOutput(true);
071:                return b;
072:            }
073:
074:            /**
075:             * Returns whether the stream valid.
076:             */
077:            public boolean isValidOut() {
078:                return validOut;
079:            }
080:
081:            /**
082:             * Opens the output stream.
083:             */
084:            public boolean openOut() {
085:                if (validOut)
086:                    return true;
087:
088:                openCon();
089:
090:                try {
091:                    os = urlc.getOutputStream();
092:                } catch (IOException e) {
093:                    ReportError.reportError(util.ReportError.INTERNAL,
094:                            "PostConnection", "openOut",
095:                            Messages.DATAOUTPUTSTREAMOPENFAIL);
096:                    return false;
097:                }
098:
099:                dos = new DataOutputStream(os);
100:
101:                validOut = true;
102:                return true;
103:            }
104:
105:            /**
106:             * Closes the output stream.
107:             */
108:            public boolean closeOut() {
109:                if (!validOut)
110:                    return true;
111:
112:                validOut = false;
113:
114:                try {
115:                    dos.close();
116:                } catch (IOException e) {
117:                    ReportError.reportError(util.ReportError.INTERNAL,
118:                            "PostConnection", "closeOut",
119:                            Messages.DATAOUTPUTSTREAMCLOSEFAIL);
120:                    return false;
121:                }
122:
123:                return true;
124:            }
125:
126:            /**
127:             * Write bytes to the data output stream.
128:             * @param s bytes to write
129:             */
130:            public void writeBytes(String s) {
131:                if (validOut) {
132:                    try {
133:                        dos.writeBytes(s);
134:                    } catch (IOException e) {
135:                        ReportError.reportError(util.ReportError.INTERNAL,
136:                                "PostConnection", "writeBytes",
137:                                Messages.DATAOUTPUTSTREAMWRITEFAIL);
138:                    }
139:                }
140:            }
141:
142:            /**
143:             * Encapsulated post action.
144:             * @param s data to post
145:             */
146:            public String doWrite(String s) {
147:                return doWrite(s, true);
148:            }
149:
150:            /**
151:             * Encapsulated post action.
152:             * @param s data to post
153:             * @param b do read after post
154:             */
155:            public String doWrite(String s, boolean b) {
156:                if (openOut() == false) {
157:                    return null;
158:                }
159:
160:                writeBytes(s);
161:
162:                if (closeOut() == false) {
163:                    return null;
164:                }
165:
166:                if (b) {
167:                    String response = doRead();
168:                    if (response != null) {
169:                        response.trim();
170:                    }
171:                    return response;
172:                }
173:
174:                return null;
175:            }
176:
177:            /**
178:             * Encapsulated post action.
179:             * Assumes that a read should be attempted after the post.
180:             * @param url target url
181:             * @param s data to post
182:             */
183:            public static String doWrite(String url, String s) {
184:                return doWrite(url, s, true);
185:            }
186:
187:            /**
188:             * Encapsulated post action.
189:             * @param url target url
190:             * @param s data to post
191:             * @param b do a get after the post
192:             */
193:            public static String doWrite(String url, String s, boolean b) {
194:                PostConnection pc = new PostConnection(url);
195:
196:                if (pc.openOut() == false) {
197:                    return null;
198:                }
199:
200:                pc.writeBytes(s);
201:
202:                if (pc.closeOut() == false) {
203:                    return null;
204:                }
205:
206:                if (b) {
207:                    String response = pc.doRead();
208:                    if (response != null) {
209:                        response.trim();
210:                    }
211:                    return response;
212:                }
213:
214:                return null;
215:            }
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.