Index: java/org/apache/commons/httpclient/methods/ByteArrayRequestEntity.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/ByteArrayRequestEntity.java,v
retrieving revision 1.1
diff -u -r1.1 ByteArrayRequestEntity.java
--- java/org/apache/commons/httpclient/methods/ByteArrayRequestEntity.java 28 Apr 2004 02:23:17 -0000 1.1
+++ java/org/apache/commons/httpclient/methods/ByteArrayRequestEntity.java 28 Apr 2004 20:08:29 -0000
@@ -42,11 +42,24 @@
private byte[] content;
/**
+ * Creates a new entity with the given content.
+ *
+ * @param content The content to set.
+ */
+ public ByteArrayRequestEntity(final byte[] content) {
+ super();
+ if (content == null) {
+ throw new IllegalArgumentException("The content cannot be null");
+ }
+ this.content = content;
+ }
+
+ /**
* Creates a new entity with no content. The content must be set before this entity can be
* used.
*/
public ByteArrayRequestEntity() {
- super();
+ this(null);
}
/**
Index: java/org/apache/commons/httpclient/methods/InputStreamRequestEntity.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/InputStreamRequestEntity.java,v
retrieving revision 1.1
diff -u -r1.1 InputStreamRequestEntity.java
--- java/org/apache/commons/httpclient/methods/InputStreamRequestEntity.java 28 Apr 2004 02:23:17 -0000 1.1
+++ java/org/apache/commons/httpclient/methods/InputStreamRequestEntity.java 28 Apr 2004 20:08:30 -0000
@@ -53,9 +53,39 @@
private byte[] buffer = null;
/**
+ * Creates a new InputStreamRequestEntity with the given content of the given length
+ *
+ * @param inputStream The content to set.
+ * @param contentLength The content size in bytes or any of
+ * {@link EntityEnclosingMethod#CONTENT_LENGTH_AUTO CONTENT_LENGTH_AUTO},
+ * {@link EntityEnclosingMethod#CONTENT_LENGTH_CHUNKED CONTENT_LENGTH_CHUNKED}. If the number
+ * of bytes or CONTENT_LENGTH_CHUNKED is specified the content will not be
+ * buffered when {@link #getContentLength()} is called.
+ */
+ public InputStreamRequestEntity(final InputStream inputStream, long contentLength) {
+ super();
+ this.content = inputStream;
+ this.contentLength = contentLength;
+ }
+
+ /**
+ * Creates a new InputStreamRequestEntity with the given content. The content will be
+ * buffered when {@link #getContentLength()} is called, if the content length is not
+ * specified using {@link #setContentLength(long)}
+ *
+ * @param inputStream The content to set.
+ *
+ * @see #setContentLength(long)
+ */
+ public InputStreamRequestEntity(final InputStream inputStream) {
+ this(inputStream, EntityEnclosingMethod.CONTENT_LENGTH_AUTO);
+ }
+
+ /**
* Creates a new InputStreamRequestEntity with no content.
*/
public InputStreamRequestEntity() {
+ this(null, EntityEnclosingMethod.CONTENT_LENGTH_AUTO);
}
/**
Index: java/org/apache/commons/httpclient/methods/StringRequestEntity.java
===================================================================
RCS file: java/org/apache/commons/httpclient/methods/StringRequestEntity.java
diff -N java/org/apache/commons/httpclient/methods/StringRequestEntity.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/org/apache/commons/httpclient/methods/StringRequestEntity.java 28 Apr 2004 20:08:30 -0000
@@ -0,0 +1,114 @@
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+package org.apache.commons.httpclient.methods;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+
+/**
+ * A RequestEntity that contains a String.
+ */
+public class StringRequestEntity implements RequestEntity {
+
+ /** The content */
+ private String content;
+
+ /** The charset */
+ private String charset;
+
+ /**
+ * Creates a new entity with the given content and the given charset
+ *
+ * @param content The content to set.
+ * @param charset The charset of the content.
+ */
+ public StringRequestEntity(final String content, final String charset) {
+ super();
+ if (content == null) {
+ throw new IllegalArgumentException("The content cannot be null");
+ }
+ this.content = content;
+ this.charset = charset;
+ }
+
+ /**
+ * Creates a new entity with the given content
+ *
+ * @param content The content to set.
+ */
+ public StringRequestEntity(final String content) {
+ this(content, null);
+ }
+
+ /**
+ * @return true
+ */
+ public boolean isRepeatable() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.httpclient.RequestEntity#writeRequest(java.io.OutputStream)
+ */
+ public void writeRequest(OutputStream out) throws IOException {
+ Reader reader = new StringReader(this.content);
+ Writer writer = null;
+ if (this.charset != null) {
+ writer = new OutputStreamWriter(out, this.charset);
+ } else {
+ writer = new OutputStreamWriter(out);
+ }
+ char[] tmp = new char[2048];
+ int i = 0;
+ while ((i = reader.read(tmp)) >= 0) {
+ writer.write(tmp, 0, i);
+ }
+ }
+
+ /**
+ * @return The length of the content.
+ */
+ public long getContentLength() {
+ return content.length();
+ }
+
+ /**
+ * @return Returns the content.
+ */
+ public String getContent() {
+ return this.content;
+ }
+
+}