hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r936050 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ httpcore-nio/src/main/java/org/apache/http/nio/entity/ httpcore-nio/src/main/java/org/apache/http/nio/util/ httpcore-nio/src/test/java/...
Date Tue, 20 Apr 2010 20:15:47 GMT
Author: olegk
Date: Tue Apr 20 20:15:47 2010
New Revision: 936050

URL: http://svn.apache.org/viewvc?rev=936050&view=rev
Log:
IdentityInputStream#available no longer attempts to read from the session input buffer

Added:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/BufferInfo.java
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkEncoder.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/BufferInfo.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/IdentityInputStream.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestSessionBuffers.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkEncoder.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkEncoder.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkEncoder.java
Tue Apr 20 20:15:47 2010
@@ -32,8 +32,8 @@ import java.nio.ByteBuffer;
 import java.nio.channels.WritableByteChannel;
 
 import org.apache.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.http.io.BufferInfo;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
-import org.apache.http.nio.util.BufferInfo;
 import org.apache.http.util.CharArrayBuffer;
 
 /**

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentInputStream.java
Tue Apr 20 20:15:47 2010
@@ -30,7 +30,7 @@ package org.apache.http.nio.entity;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.http.nio.util.BufferInfo;
+import org.apache.http.io.BufferInfo;
 import org.apache.http.nio.util.ContentInputBuffer;
 
 /**

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/BufferInfo.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/BufferInfo.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/BufferInfo.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/BufferInfo.java
Tue Apr 20 20:15:47 2010
@@ -31,7 +31,10 @@ package org.apache.http.nio.util;
  * Basic buffer properties.
  *
  * @since 4.0
+ * 
+ * @deprecated Use {@link org.apache.http.io.BufferInfo}
  */
+@Deprecated
 public interface BufferInfo {
 
     int length();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java
Tue Apr 20 20:15:47 2010
@@ -29,6 +29,8 @@ package org.apache.http.nio.util;
 
 import java.nio.ByteBuffer;
 
+import org.apache.http.io.BufferInfo;
+
 /**
  * A buffer that expand its capacity on demand using {@link ByteBufferAllocator}
  * interface. Internally, this class is backed by an instance of 
@@ -38,7 +40,8 @@ import java.nio.ByteBuffer;
  *
  * @since 4.0
  */
-public class ExpandableBuffer implements BufferInfo {
+@SuppressWarnings("deprecation")
+public class ExpandableBuffer implements BufferInfo, org.apache.http.nio.util.BufferInfo
{
     
     public final static int INPUT_MODE = 0;
     public final static int OUTPUT_MODE = 1;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
Tue Apr 20 20:15:47 2010
@@ -38,6 +38,7 @@ import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.http.io.BufferInfo;
 import org.apache.http.impl.io.HttpTransportMetricsImpl;
 import org.apache.http.impl.nio.reactor.SessionOutputBufferImpl;
 import org.apache.http.mockup.MockupDecoder;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java
Tue Apr 20 20:15:47 2010
@@ -30,6 +30,7 @@ package org.apache.http.impl.io;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.http.io.BufferInfo;
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.params.CoreConnectionPNames;
@@ -58,7 +59,7 @@ import org.apache.http.util.CharArrayBuf
  * </ul>
  * @since 4.0
  */
-public abstract class AbstractSessionInputBuffer implements SessionInputBuffer {
+public abstract class AbstractSessionInputBuffer implements SessionInputBuffer, BufferInfo
{
 
     private InputStream instream;
     private byte[] buffer;
@@ -103,7 +104,28 @@ public abstract class AbstractSessionInp
         this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT,
512);
         this.metrics = new HttpTransportMetricsImpl();
     }
+
+    /**
+     * @since 4.1
+     */
+    public int capacity() {
+        return this.buffer.length;
+    }
+
+    /**
+     * @since 4.1
+     */
+    public int length() {
+        return this.bufferlen - this.bufferpos;
+    }
     
+    /**
+     * @since 4.1
+     */
+    public int available() {
+        return capacity() - length();
+    }
+
     protected int fillBuffer() throws IOException {
         // compact the buffer if necessary
         if (this.bufferpos > 0) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java
Tue Apr 20 20:15:47 2010
@@ -30,6 +30,7 @@ package org.apache.http.impl.io;
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.http.io.BufferInfo;
 import org.apache.http.io.SessionOutputBuffer;
 import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.params.CoreConnectionPNames;
@@ -57,7 +58,7 @@ import org.apache.http.util.CharArrayBuf
  *
  * @since 4.0
  */
-public abstract class AbstractSessionOutputBuffer implements SessionOutputBuffer {
+public abstract class AbstractSessionOutputBuffer implements SessionOutputBuffer, BufferInfo
{
 
     private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
     
@@ -96,6 +97,27 @@ public abstract class AbstractSessionOut
         this.metrics = new HttpTransportMetricsImpl();
     }
     
+    /**
+     * @since 4.1
+     */
+    public int capacity() {
+        return this.buffer.capacity();
+    }
+
+    /**
+     * @since 4.1
+     */
+    public int length() {
+        return this.buffer.length();
+    }
+    
+    /**
+     * @since 4.1
+     */
+    public int available() {
+        return capacity() - length();
+    }
+
     protected void flushBuffer() throws IOException {
         int len = this.buffer.length();
         if (len > 0) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/IdentityInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/IdentityInputStream.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/IdentityInputStream.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/IdentityInputStream.java
Tue Apr 20 20:15:47 2010
@@ -30,6 +30,7 @@ package org.apache.http.impl.io;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.http.io.BufferInfo;
 import org.apache.http.io.SessionInputBuffer;
 
 /**
@@ -64,8 +65,8 @@ public class IdentityInputStream extends
     }
     
     public int available() throws IOException {
-        if (!this.closed && this.in.isDataAvailable(10)) {
-            return 1;
+        if (this.in instanceof BufferInfo) {
+            return ((BufferInfo) this.in).length();
         } else {
             return 0;
         }

Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/BufferInfo.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/BufferInfo.java?rev=936050&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/BufferInfo.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/BufferInfo.java
Tue Apr 20 20:15:47 2010
@@ -0,0 +1,58 @@
+/*
+ * ====================================================================
+ * 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.io;
+
+/**
+ * Basic buffer properties.
+ *
+ * @since 4.1
+ */
+public interface BufferInfo {
+
+    /**
+     * Return length data stored in the buffer
+     * 
+     * @return data length
+     */
+    int length();
+
+    /**
+     * Returns total capacity of the buffer
+     * 
+     * @return total capacity
+     */
+    int capacity();
+
+    /**
+     * Returns available space in the buffer.
+     * 
+     * @return available space.
+     */
+    int available();
+
+}

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestSessionBuffers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestSessionBuffers.java?rev=936050&r1=936049&r2=936050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestSessionBuffers.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestSessionBuffers.java
Tue Apr 20 20:15:47 2010
@@ -94,6 +94,24 @@ public class TestSessionBuffers extends 
             //expected
         }
     }
+
+    public void testBasicBufferProperties() throws Exception {
+        SessionInputBufferMockup inbuffer = new SessionInputBufferMockup(new byte[] { 1,
2 , 3});
+        assertEquals(SessionInputBufferMockup.BUFFER_SIZE, inbuffer.capacity());
+        assertEquals(SessionInputBufferMockup.BUFFER_SIZE, inbuffer.available());
+        assertEquals(0, inbuffer.length());
+        inbuffer.read();
+        assertEquals(SessionInputBufferMockup.BUFFER_SIZE - 2, inbuffer.available());
+        assertEquals(2, inbuffer.length());
+
+        SessionOutputBufferMockup outbuffer = new SessionOutputBufferMockup(); 
+        assertEquals(SessionOutputBufferMockup.BUFFER_SIZE, outbuffer.capacity());
+        assertEquals(SessionOutputBufferMockup.BUFFER_SIZE, outbuffer.available());
+        assertEquals(0, outbuffer.length());
+        outbuffer.write(new byte[] {1, 2, 3});
+        assertEquals(SessionOutputBufferMockup.BUFFER_SIZE - 3, outbuffer.available());
+        assertEquals(3, outbuffer.length());
+    }
     
     public void testBasicReadWriteLine() throws Exception {
         



Mime
View raw message