You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2005/04/19 00:17:17 UTC

svn commit: r161807 - in jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity: BufferedHttpIncomingEntity.java ByteArrayEntity.java InputStreamEntity.java StringEntity.java

Author: olegk
Date: Mon Apr 18 15:17:16 2005
New Revision: 161807

URL: http://svn.apache.org/viewcvs?view=rev&rev=161807
Log:
HttpOutgoingEntity interface impls

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java
      - copied, changed from r161634, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java   (with props)
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java   (with props)
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java   (with props)

Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java (from r161634, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java?view=diff&rev=161807&p1=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java&r1=161634&p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java&r2=161807
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java Mon Apr 18 15:17:16 2005
@@ -44,12 +44,12 @@
  * 
  * @since 4.0
  */
-public class BufferedHttpEntity implements HttpIncomingEntity {
+public class BufferedHttpIncomingEntity implements HttpIncomingEntity {
     
     private final HttpIncomingEntity source;
     private final byte[] buffer;
     
-    public BufferedHttpEntity(final HttpIncomingEntity entity) throws IOException {
+    public BufferedHttpIncomingEntity(final HttpIncomingEntity entity) throws IOException {
         super();
         if (entity == null) {
             throw new IllegalArgumentException("HTTP entity may not be null");

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java?view=auto&rev=161807
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java Mon Apr 18 15:17:16 2005
@@ -0,0 +1,94 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.entity;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.http.HttpOutgoingEntity;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class ByteArrayEntity implements HttpOutgoingEntity {
+
+    private final static String DEFAULT_CONTENT_TYPE = "application/octet-stream";
+
+    private final byte[] source;
+    private String contentType = DEFAULT_CONTENT_TYPE;
+    private boolean chunked = false;
+
+    public ByteArrayEntity(final byte[] b) {
+        super();
+        if (b == null) {
+            throw new IllegalArgumentException("Source byte array may not be null");
+        }
+        this.source = b;
+    }
+
+    public boolean isRepeatable() {
+        return true;
+    }
+
+    public boolean isChunked() {
+        return this.chunked;
+    }
+
+    public void setChunked(boolean b) {
+        this.chunked = b;
+    }
+
+    public long getContentLength() {
+        return this.source.length;
+    }
+    
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    public void setContentType(final String s) {
+        this.contentType = s;
+    }
+
+    public void writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        outstream.write(this.source);
+        outstream.flush();
+    }
+
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java?view=auto&rev=161807
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java Mon Apr 18 15:17:16 2005
@@ -0,0 +1,106 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.entity;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.http.HttpOutgoingEntity;
+import org.apache.http.io.ContentLengthInputStream;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class InputStreamEntity implements HttpOutgoingEntity {
+
+    private final static String DEFAULT_CONTENT_TYPE = "application/octet-stream";
+
+    private final InputStream source;
+    private final long length;
+    private String contentType = DEFAULT_CONTENT_TYPE;
+    private boolean chunked = false;
+
+    public InputStreamEntity(final InputStream instream, long length) {
+        super();
+        if (instream == null) {
+            throw new IllegalArgumentException("Source input stream may not be null");
+        }
+        this.source = instream;
+        this.length = length;
+    }
+
+    public boolean isRepeatable() {
+        return false;
+    }
+
+    public boolean isChunked() {
+        return this.chunked;
+    }
+
+    public void setChunked(boolean b) {
+        this.chunked = b;
+    }
+
+    public long getContentLength() {
+        return this.length;
+    }
+    
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    public void setContentType(final String s) {
+        this.contentType = s;
+    }
+
+    public void writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        InputStream instream = this.source;
+        if (this.length >= 0) {
+            instream = new ContentLengthInputStream(instream, this.length);
+        }
+        int l;
+        byte[] tmp = new byte[1024];
+        while ((l = instream.read(tmp)) != -1) {
+            outstream.write(tmp, 0, l);
+        }
+        outstream.flush();
+    }
+
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java?view=auto&rev=161807
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java Mon Apr 18 15:17:16 2005
@@ -0,0 +1,103 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.entity;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.http.HttpOutgoingEntity;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class StringEntity implements HttpOutgoingEntity {
+
+    private final static String DEFAULT_CONTENT_TYPE = "text/plain; charset=";
+
+    private final String source;
+    private String contentType = null;
+    private boolean chunked = false;
+
+    public StringEntity(final String s, final String charset) {
+        super();
+        if (s == null) {
+            throw new IllegalArgumentException("Source string may not be null");
+        }
+        this.source = s;
+        if (charset != null) {
+            this.contentType = DEFAULT_CONTENT_TYPE + charset;
+        }
+    }
+
+    public StringEntity(final String s) {
+        this(s, null);
+    }
+
+    public boolean isRepeatable() {
+        return true;
+    }
+
+    public boolean isChunked() {
+        return this.chunked;
+    }
+
+    public void setChunked(boolean b) {
+        this.chunked = b;
+    }
+
+    public long getContentLength() {
+        return this.source.length();
+    }
+    
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    public void setContentType(final String s) {
+        this.contentType = s;
+    }
+
+    public void writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        String charset = EntityConsumer.getContentCharSet(this);
+        byte[] content = this.source.getBytes(charset);
+        outstream.write(content);
+        outstream.flush();
+    }
+
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain