Source Code Cross Referenced for StringRequestEntity.java in  » Net » Apache-common-HttpClient » org » apache » commons » httpclient » methods » 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 » Apache common HttpClient » org.apache.commons.httpclient.methods 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $HeadURL: https://svn.apache.org/repos/asf/jakarta/httpcomponents/oac.hc3x/tags/HTTPCLIENT_3_1/src/java/org/apache/commons/httpclient/methods/StringRequestEntity.java $
003:         * $Revision: 480424 $
004:         * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005:         *
006:         * ====================================================================
007:         *
008:         *  Licensed to the Apache Software Foundation (ASF) under one or more
009:         *  contributor license agreements.  See the NOTICE file distributed with
010:         *  this work for additional information regarding copyright ownership.
011:         *  The ASF licenses this file to You under the Apache License, Version 2.0
012:         *  (the "License"); you may not use this file except in compliance with
013:         *  the License.  You may obtain a copy of the License at
014:         *
015:         *      http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         *  Unless required by applicable law or agreed to in writing, software
018:         *  distributed under the License is distributed on an "AS IS" BASIS,
019:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020:         *  See the License for the specific language governing permissions and
021:         *  limitations under the License.
022:         * ====================================================================
023:         *
024:         * This software consists of voluntary contributions made by many
025:         * individuals on behalf of the Apache Software Foundation.  For more
026:         * information on the Apache Software Foundation, please see
027:         * <http://www.apache.org/>.
028:         *
029:         * [Additional notices, if required by prior licensing conditions]
030:         *
031:         */
032:        package org.apache.commons.httpclient.methods;
033:
034:        import java.io.IOException;
035:        import java.io.OutputStream;
036:        import java.io.UnsupportedEncodingException;
037:
038:        import org.apache.commons.httpclient.HeaderElement;
039:        import org.apache.commons.httpclient.NameValuePair;
040:
041:        /**
042:         * A RequestEntity that contains a String.
043:         * 
044:         * @since 3.0
045:         */
046:        public class StringRequestEntity implements  RequestEntity {
047:
048:            /** The content */
049:            private byte[] content;
050:
051:            /** The charset */
052:            private String charset;
053:
054:            /** The content type (i.e. text/html; charset=EUC-JP). */
055:            private String contentType;
056:
057:            /**
058:             * <p>Creates a new entity with the given content. This constructor 
059:             * will use the default platform charset to convert the content string 
060:             * and will provide no content type.</p>
061:             *  
062:             * @see #StringRequestEntity(String, String, String)
063:             * 
064:             * @param content The content to set.
065:             * 
066:             * @deprecated use {@link #StringRequestEntity(String, String, String)} instead
067:             */
068:            public StringRequestEntity(String content) {
069:                super ();
070:                if (content == null) {
071:                    throw new IllegalArgumentException(
072:                            "The content cannot be null");
073:                }
074:                this .contentType = null;
075:                this .charset = null;
076:                this .content = content.getBytes();
077:            }
078:
079:            /**
080:             * Creates a new entity with the given content, content type, and charset.
081:             *  
082:             * @param content The content to set.
083:             * @param contentType The type of the content, or <code>null</code>.  The value retured 
084:             *   by {@link #getContentType()}.  If this content type contains a charset and the charset
085:             *   parameter is null, the content's type charset will be used.
086:             * @param charset The charset of the content, or <code>null</code>.  Used to convert the 
087:             *   content to bytes.  If the content type does not contain a charset and charset is not null,
088:             *   then the charset will be appended to the content type.
089:             */
090:            public StringRequestEntity(String content, String contentType,
091:                    String charset) throws UnsupportedEncodingException {
092:                super ();
093:                if (content == null) {
094:                    throw new IllegalArgumentException(
095:                            "The content cannot be null");
096:                }
097:
098:                this .contentType = contentType;
099:                this .charset = charset;
100:
101:                // resolve the content type and the charset
102:                if (contentType != null) {
103:                    HeaderElement[] values = HeaderElement
104:                            .parseElements(contentType);
105:                    NameValuePair charsetPair = null;
106:                    for (int i = 0; i < values.length; i++) {
107:                        if ((charsetPair = values[i]
108:                                .getParameterByName("charset")) != null) {
109:                            // charset found
110:                            break;
111:                        }
112:                    }
113:                    if (charset == null && charsetPair != null) {
114:                        // use the charset from the content type
115:                        this .charset = charsetPair.getValue();
116:                    } else if (charset != null && charsetPair == null) {
117:                        // append the charset to the content type
118:                        this .contentType = contentType + "; charset=" + charset;
119:                    }
120:                }
121:                if (this .charset != null) {
122:                    this .content = content.getBytes(this .charset);
123:                } else {
124:                    this .content = content.getBytes();
125:                }
126:            }
127:
128:            /* (non-Javadoc)
129:             * @see org.apache.commons.httpclient.methods.RequestEntity#getContentType()
130:             */
131:            public String getContentType() {
132:                return contentType;
133:            }
134:
135:            /**
136:             * @return <code>true</code>
137:             */
138:            public boolean isRepeatable() {
139:                return true;
140:            }
141:
142:            /* (non-Javadoc)
143:             * @see org.apache.commons.httpclient.RequestEntity#writeRequest(java.io.OutputStream)
144:             */
145:            public void writeRequest(OutputStream out) throws IOException {
146:                if (out == null) {
147:                    throw new IllegalArgumentException(
148:                            "Output stream may not be null");
149:                }
150:                out.write(this .content);
151:                out.flush();
152:            }
153:
154:            /**
155:             * @return The length of the content.
156:             */
157:            public long getContentLength() {
158:                return this .content.length;
159:            }
160:
161:            /**
162:             * @return Returns the content.
163:             */
164:            public String getContent() {
165:                if (this .charset != null) {
166:                    try {
167:                        return new String(this .content, this .charset);
168:                    } catch (UnsupportedEncodingException e) {
169:                        return new String(this .content);
170:                    }
171:                } else {
172:                    return new String(this .content);
173:                }
174:            }
175:
176:            /**
177:             * @return Returns the charset used to convert the content to bytes. <code>null</code> if
178:             * no charset as been specified.
179:             */
180:            public String getCharset() {
181:                return charset;
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.