hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r602520 - in /jakarta/httpcomponents/httpcore/trunk: module-main/src/main/java/org/apache/http/entity/ module-main/src/main/java/org/apache/http/impl/ module-main/src/main/java/org/apache/http/message/ module-nio/src/examples/org/apache/htt...
Date Sat, 08 Dec 2007 17:42:32 GMT
Author: olegk
Date: Sat Dec  8 09:42:26 2007
New Revision: 602520

URL: http://svn.apache.org/viewvc?rev=602520&view=rev
Log:
HTTPCORE-68: NIO specific entity classes

Added:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/ByteArrayNIOEntity.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/FileNIOEntity.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/HttpNIOEntity.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/StringNIOEntity.java
  (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/ByteArrayEntity.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/FileEntity.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/StringEntity.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicTokenIterator.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/ByteArrayEntity.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/ByteArrayEntity.java?rev=602520&r1=602519&r2=602520&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/ByteArrayEntity.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/ByteArrayEntity.java
Sat Dec  8 09:42:26 2007
@@ -37,7 +37,7 @@
 import java.io.OutputStream;
 
 /**
- * A self-contained entity obtaining content from a byte array.
+ *  An entity whose content is retrieved from a byte array.
  *
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
@@ -47,7 +47,7 @@
  */
 public class ByteArrayEntity extends AbstractHttpEntity {
 
-    private final byte[] content;
+    protected final byte[] content;
 
     public ByteArrayEntity(final byte[] b) {
         super();        

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/FileEntity.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/FileEntity.java?rev=602520&r1=602519&r2=602520&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/FileEntity.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/FileEntity.java
Sat Dec  8 09:42:26 2007
@@ -38,7 +38,7 @@
 import java.io.OutputStream;
 
 /**
- * A self-contained entity obtaining content from a file.
+ * An entity whose content is retrieved from a file.
  *
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
@@ -48,7 +48,7 @@
  */
 public class FileEntity extends AbstractHttpEntity {
 
-    private final File file; 
+    protected final File file; 
 
     public FileEntity(final File file, final String contentType) {
         super();

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/StringEntity.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/StringEntity.java?rev=602520&r1=602519&r2=602520&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/StringEntity.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/entity/StringEntity.java
Sat Dec  8 09:42:26 2007
@@ -40,7 +40,7 @@
 import org.apache.http.protocol.HTTP;
 
 /**
- * A self-contained entity obtaining content from a string.
+ *  An entity whose content is retrieved from a string.
  *
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
@@ -50,7 +50,7 @@
  */
 public class StringEntity extends AbstractHttpEntity {
 
-    private final byte[] content;
+    protected final byte[] content;
 
     public StringEntity(final String s, String charset) 
             throws UnsupportedEncodingException {

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java?rev=602520&r1=602519&r2=602520&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
Sat Dec  8 09:42:26 2007
@@ -33,7 +33,6 @@
 
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpConnection;
-import org.apache.http.Header;
 import org.apache.http.HeaderIterator;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
@@ -45,7 +44,6 @@
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.TokenIterator;
 import org.apache.http.message.BasicTokenIterator;
-
 
 /**
  * Default implementation of a strategy deciding about connection re-use.

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicTokenIterator.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicTokenIterator.java?rev=602520&r1=602519&r2=602520&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicTokenIterator.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicTokenIterator.java
Sat Dec  8 09:42:26 2007
@@ -33,14 +33,9 @@
 
 import java.util.NoSuchElementException;
 
-import org.apache.http.FormattedHeader;
-import org.apache.http.Header;
-import org.apache.http.HeaderElement;
 import org.apache.http.HeaderIterator;
-import org.apache.http.TokenIterator;
 import org.apache.http.ParseException;
-
-
+import org.apache.http.TokenIterator;
 
 /**
  * Basic implementation of a {@link TokenIterator}.

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java?rev=602520&r1=602519&r2=602520&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
Sat Dec  8 09:42:26 2007
@@ -31,9 +31,7 @@
 package org.apache.http.examples.nio;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.InterruptedIOException;
 import java.io.RandomAccessFile;
 import java.io.UnsupportedEncodingException;
@@ -43,6 +41,7 @@
 import java.nio.channels.Channels;
 import java.nio.channels.FileChannel;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.Header;
@@ -56,8 +55,6 @@
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.entity.FileEntity;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.nio.DefaultServerIOEventDispatch;
@@ -65,8 +62,12 @@
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.FileContentDecoder;
+import org.apache.http.nio.FileContentEncoder;
 import org.apache.http.nio.NHttpServerConnection;
 import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.entity.ByteArrayNIOEntity;
+import org.apache.http.nio.entity.FileNIOEntity;
+import org.apache.http.nio.entity.HttpNIOEntity;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.ListeningIOReactor;
 import org.apache.http.params.BasicHttpParams;
@@ -117,7 +118,6 @@
     }
 
     private static final String CONN_STATE    = "http.conn-state";
-    private static final String OUT_CHANNEL   = "http.out-channel";
     
     static class ConnState {
 
@@ -126,7 +126,10 @@
         
         private File fileHandle;
         private RandomAccessFile inputFile;
+        private WritableByteChannel inputChannel;
+        private ReadableByteChannel outputChannel;
         private long inputCount;
+        private long outputCount;
         
         public ConnState() {
             super();
@@ -142,7 +145,6 @@
             return this.outbuf;
         }
 
-        
         public File getInputFile() throws IOException {
             if (this.fileHandle == null) {
                 this.fileHandle = File.createTempFile("tmp", ".tmp", null);
@@ -150,11 +152,22 @@
             return this.fileHandle;
         }
         
-        public FileChannel getInputChannel() throws IOException {
+        public WritableByteChannel getInputChannel() throws IOException {
             if (this.inputFile == null) {
                 this.inputFile = new RandomAccessFile(getInputFile(), "rw");
             }
-            return this.inputFile.getChannel();
+            if (this.inputChannel == null) {
+                this.inputChannel = this.inputFile.getChannel();
+            }
+            return this.inputChannel;
+        }
+        
+        public void setOutputChannel(final ReadableByteChannel channel) {
+            this.outputChannel = channel;
+        }
+        
+        public ReadableByteChannel getOutputChannel() {
+            return this.outputChannel;
         }
         
         public long getInputCount() {
@@ -165,10 +178,23 @@
             this.inputCount += count;
         }
         
+        public long getOutputCount() {
+            return this.outputCount;
+        }
+        
+        public void incrementOutputCount(long count) {
+            this.outputCount += count;
+        }
+        
         public void reset() throws IOException {
             this.inbuf.clear();
             this.outbuf.clear();
             this.inputCount = 0;
+            this.outputCount = 0;
+            if (this.inputChannel != null) {
+                this.inputChannel.close();
+                this.inputChannel = null;
+            }
             if (this.inputFile != null) {
                 this.inputFile.close();
                 this.inputFile = null;
@@ -246,6 +272,9 @@
             }
             
             HttpContext context = conn.getContext();
+
+            ConnState connState = (ConnState) context.getAttribute(CONN_STATE);
+            
             HttpResponse response =  this.responseFactory.newHttpResponse(
                     HttpVersion.HTTP_1_0, HttpStatus.SC_BAD_REQUEST, context);
             HttpParamsLinker.link(response, this.params);
@@ -256,7 +285,7 @@
             try {
                 handleException(ex, response, context);
                 this.httpProcessor.process(response, context);
-                commitResponse(conn, response);
+                commitResponse(conn, connState, response);
             } catch (HttpException ex2) {
                 shutdownConnection(conn);
                 System.err.println("Unexpected HTTP protocol error: " + ex2.getMessage());
@@ -315,30 +344,28 @@
 
             ConnState connState = (ConnState) context.getAttribute(
                     CONN_STATE);
-            
             try {
 
-                FileChannel filechannel = connState.getInputChannel();
-                
-                // Test if the decoder is capable of 
-                // direct transfer to file
-                if (decoder instanceof FileContentDecoder) {
+                WritableByteChannel channel = connState.getInputChannel();
+                long transferred;
+
+                // Test if the decoder is capable of direct transfer to file
+                if (decoder instanceof FileContentDecoder && channel instanceof FileChannel)
{
                     long pos = connState.getInputCount();
-                    long transferred = ((FileContentDecoder) decoder).transfer(
-                            filechannel, pos, Integer.MAX_VALUE);
-                    connState.incrementInputCount(transferred);
+                    transferred = ((FileContentDecoder) decoder).transfer(
+                            (FileChannel) channel, pos, Integer.MAX_VALUE);
                 } else {
                     ByteBuffer buf = connState.getInbuf();
                     decoder.read(buf);
                     buf.flip();
-                    int transferred = filechannel.write(buf);
+                    transferred = channel.write(buf);
                     buf.compact();
-                    connState.incrementInputCount(transferred);
                 }
+                connState.incrementInputCount(transferred);
                 
                 if (decoder.isCompleted()) {
                     // Request entity has been fully received
-                    filechannel.close();
+                    channel.close();
                     doService(conn, connState);
                 }
                 
@@ -356,21 +383,33 @@
 
             ConnState connState = (ConnState) context.getAttribute(
                     CONN_STATE);
-            ReadableByteChannel channel = (ReadableByteChannel) context.getAttribute(
-                    OUT_CHANNEL);
-
             HttpResponse response = conn.getHttpResponse();
-            ByteBuffer outbuf = connState.getOutbuf();
             try {
-                int bytesRead = channel.read(outbuf);
-                if (bytesRead == -1) {
-                    encoder.complete();
+
+                ReadableByteChannel channel = connState.getOutputChannel();
+                long transferred;
+
+                // Test if the encoder is capable of direct transfer from file
+                if (encoder instanceof FileContentDecoder && channel instanceof FileChannel)
{
+                    long pos = connState.getOutputCount();
+                    transferred = ((FileContentEncoder) encoder).transfer(
+                            (FileChannel) channel, pos, Integer.MAX_VALUE);
                 } else {
-                    outbuf.flip();
-                    encoder.write(outbuf);
-                    outbuf.compact();
+                    ByteBuffer outbuf = connState.getOutbuf();
+                    transferred = channel.read(outbuf);
+                    if (transferred != -1) {
+                        outbuf.flip();
+                        encoder.write(outbuf);
+                        outbuf.compact();
+                    }
                 }
-
+                if (transferred == -1) {
+                    encoder.complete();
+                }
+                if (transferred > 0) {
+                    connState.incrementOutputCount(transferred);
+                }
+                
                 if (encoder.isCompleted()) {
                     channel.close();
                     if (!this.connStrategy.keepAlive(response, context)) {
@@ -382,23 +421,23 @@
                 shutdownConnection(conn);
                 System.err.println("I/O error: " + ex.getMessage());
             }
-
         }
 
         private void commitResponse(
                 final NHttpServerConnection conn,
+                final ConnState connState,
                 final HttpResponse response) throws HttpException, IOException {
-            ReadableByteChannel channel = null;
-            if (response.getEntity() != null) {
-                InputStream instream = response.getEntity().getContent(); 
-                if (instream instanceof FileInputStream) {
-                    channel = ((FileInputStream)instream).getChannel();
+            
+            HttpEntity entity = response.getEntity();
+            if (entity != null) {
+                ReadableByteChannel channel;
+                if (entity instanceof HttpNIOEntity) {
+                    channel = ((HttpNIOEntity) entity).getChannel();
                 } else {
-                    channel = Channels.newChannel(instream);
+                    channel = Channels.newChannel(entity.getContent());
                 }
-                
+                connState.setOutputChannel(channel);
             }
-            conn.getContext().setAttribute(OUT_CHANNEL, channel);
             conn.submitResponse(response);
         }
 
@@ -416,7 +455,7 @@
                 if (h != null) {
                     contentType = h.getValue();
                 }
-                HttpEntity entity = new FileEntity(connState.getInputFile(), contentType);
+                HttpNIOEntity entity = new FileNIOEntity(connState.getInputFile(), contentType);
                 eeRequest.setEntity(entity);
             }
             
@@ -435,7 +474,7 @@
                 handleException(ex, response, context);
             }
             this.httpProcessor.process(response, context);
-            commitResponse(conn, response);
+            commitResponse(conn, connState, response);
         }
         
         private void handleRequest(
@@ -456,7 +495,7 @@
                 response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                 byte[] msg = EncodingUtils.getAsciiBytes(
                         file.getName() + ": not found");
-                ByteArrayEntity entity = new ByteArrayEntity(msg);
+                ByteArrayNIOEntity entity = new ByteArrayNIOEntity(msg);
                 entity.setContentType("text/plain; charset=US-ASCII");
                 response.setEntity(entity);
                 
@@ -465,13 +504,13 @@
                 response.setStatusCode(HttpStatus.SC_FORBIDDEN);
                 byte[] msg = EncodingUtils.getAsciiBytes(
                         file.getName() + ": access denied");
-                ByteArrayEntity entity = new ByteArrayEntity(msg);
+                ByteArrayNIOEntity entity = new ByteArrayNIOEntity(msg);
                 entity.setContentType("text/plain; charset=US-ASCII");
                 response.setEntity(entity);
 
             } else {
 
-                FileEntity entity = new FileEntity(file, "text/html");
+                FileNIOEntity entity = new FileNIOEntity(file, "text/html");
                 response.setEntity(entity);
                 
             }
@@ -484,7 +523,7 @@
             response.setStatusLine(HttpVersion.HTTP_1_0, HttpStatus.SC_BAD_REQUEST);
             byte[] msg = EncodingUtils.getAsciiBytes(
                     "Malformed HTTP request: " + ex.getMessage());
-            ByteArrayEntity entity = new ByteArrayEntity(msg);
+            ByteArrayNIOEntity entity = new ByteArrayNIOEntity(msg);
             entity.setContentType("text/plain; charset=US-ASCII");
             response.setEntity(entity);
         }

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/ByteArrayNIOEntity.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/ByteArrayNIOEntity.java?rev=602520&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/ByteArrayNIOEntity.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/ByteArrayNIOEntity.java
Sat Dec  8 09:42:26 2007
@@ -0,0 +1,62 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.nio.entity;
+
+import java.io.IOException;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.ByteArrayEntity;
+
+/**
+ * An entity whose content is retrieved from a byte array. In addition to the 
+ * standard {@link HttpEntity} interface this class also implements NIO specific 
+ * {@link HttpNIOEntity}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision:$
+ * 
+ * @since 4.0
+ */
+public class ByteArrayNIOEntity extends ByteArrayEntity implements HttpNIOEntity {
+
+    public ByteArrayNIOEntity(final byte[] b) {
+        super(b);
+    }
+
+    public ReadableByteChannel getChannel() throws IOException {
+        return Channels.newChannel(getContent());
+    }
+
+}

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

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

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

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/FileNIOEntity.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/FileNIOEntity.java?rev=602520&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/FileNIOEntity.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/FileNIOEntity.java
Sat Dec  8 09:42:26 2007
@@ -0,0 +1,64 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.nio.entity;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.ReadableByteChannel;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.FileEntity;
+
+/**
+ * An entity whose content is retrieved from from a file. In addition to the standard 
+ * {@link HttpEntity} interface this class also implements NIO specific 
+ * {@link HttpNIOEntity}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision:$
+ * 
+ * @since 4.0
+ */
+public class FileNIOEntity extends FileEntity implements HttpNIOEntity {
+
+    public FileNIOEntity(final File file, final String contentType) {
+        super(file, contentType);
+    }
+
+    public ReadableByteChannel getChannel() throws IOException {
+        RandomAccessFile rafile = new RandomAccessFile(this.file, "r");
+        return rafile.getChannel();
+    }
+
+}

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

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

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

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/HttpNIOEntity.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/HttpNIOEntity.java?rev=602520&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/HttpNIOEntity.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/HttpNIOEntity.java
Sat Dec  8 09:42:26 2007
@@ -0,0 +1,43 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.nio.entity;
+
+import java.io.IOException;
+import java.nio.channels.ReadableByteChannel;
+
+import org.apache.http.HttpEntity;
+
+public interface HttpNIOEntity extends HttpEntity  {
+
+    ReadableByteChannel getChannel() throws IOException;
+    
+}

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

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

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

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/StringNIOEntity.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/StringNIOEntity.java?rev=602520&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/StringNIOEntity.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/entity/StringNIOEntity.java
Sat Dec  8 09:42:26 2007
@@ -0,0 +1,65 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.nio.entity;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.StringEntity;
+
+/**
+ * An entity whose content is retrieved from a string. In addition to the 
+ * standard {@link HttpEntity} interface this class also implements NIO specific 
+ * {@link HttpNIOEntity}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision:$
+ * 
+ * @since 4.0
+ */
+public class StringNIOEntity extends StringEntity implements HttpNIOEntity {
+
+    public StringNIOEntity(
+            final String s, 
+            String charset) throws UnsupportedEncodingException {
+        super(s, charset);
+    }
+
+    public ReadableByteChannel getChannel() throws IOException {
+        return Channels.newChannel(getContent());
+    }
+
+}

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

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

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



Mime
View raw message