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 2006/05/20 18:55:43 UTC

svn commit: r408032 - in /jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity: ContentProducer.java EntityTemplate.java

Author: olegk
Date: Sat May 20 09:55:43 2006
New Revision: 408032

URL: http://svn.apache.org/viewvc?rev=408032&view=rev
Log:
Added ContentProducer interface and EntityTemplate class

Added:
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/ContentProducer.java   (with props)
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/EntityTemplate.java   (with props)

Added: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/ContentProducer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/ContentProducer.java?rev=408032&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/ContentProducer.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/ContentProducer.java Sat May 20 09:55:43 2006
@@ -0,0 +1,51 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 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;
+
+/**
+ * An abstract entity content producer.
+ *
+ *<p>Content producers are expected to be able to produce their 
+ * content multiple times</p>
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public interface ContentProducer {
+
+    void writeTo(OutputStream outstream) throws IOException;
+
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/ContentProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/ContentProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/ContentProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/EntityTemplate.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/EntityTemplate.java?rev=408032&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/EntityTemplate.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/EntityTemplate.java Sat May 20 09:55:43 2006
@@ -0,0 +1,84 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 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;
+
+/**
+ * Entity that delegates the process of content generation to an abstract
+ * content producer.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class EntityTemplate extends AbstractHttpEntity {
+
+    private final ContentProducer contentproducer;
+    
+    public EntityTemplate(final ContentProducer contentproducer) {
+        super();
+        if (this.contentproducer == null) {
+            throw new IllegalArgumentException("Content producer may not be null");
+        }
+        this.contentproducer = contentproducer; 
+    }
+
+    public long getContentLength() {
+        return -1;
+    }
+
+    public InputStream getContent() {
+        throw new UnsupportedOperationException("Entity template does not implement getContent()");
+    }
+
+    public boolean isRepeatable() {
+        return true;
+    }
+
+    public void writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        this.contentproducer.writeTo(outstream);
+    }
+
+    public boolean isStreaming() {
+        return true;
+    }
+
+    public void consumeContent() throws IOException {
+    }
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/EntityTemplate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/EntityTemplate.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/entity/EntityTemplate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain