You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ra...@apache.org on 2006/11/02 16:34:54 UTC

svn commit: r470389 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java

Author: rajdavies
Date: Thu Nov  2 07:34:53 2006
New Revision: 470389

URL: http://svn.apache.org/viewvc?view=rev&rev=470389
Log:
optimized

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java?view=diff&rev=470389&r1=470388&r2=470389
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpBufferedOutputStream.java Thu Nov  2 07:34:53 2006
@@ -32,6 +32,7 @@
 public class TcpBufferedOutputStream extends FilterOutputStream {
     private final static int BUFFER_SIZE = 8192;
     private byte[] buffer;
+    private int bufferlen;
     private int count;
     private boolean closed;
 
@@ -58,6 +59,7 @@
             throw new IllegalArgumentException("Buffer size <= 0");
         }
         buffer = new byte[size];
+        bufferlen=size;
     }
 
     /**
@@ -67,8 +69,7 @@
      * @throws IOException
      */
     public void write(int b) throws IOException {
-        checkClosed();
-        if (availableBufferToWrite() < 1) {
+        if ((bufferlen-count) < 1) {
             flush();
         }
         buffer[count++] = (byte) b;
@@ -84,8 +85,7 @@
      * @throws IOException
      */
     public void write(byte b[], int off, int len) throws IOException {
-        checkClosed();
-        if (availableBufferToWrite() < len) {
+        if ((bufferlen-count) < len) {
             flush();
         }
         if (buffer.length >= len) {
@@ -127,16 +127,10 @@
      *
      * @throws IOException
      */
-    protected void checkClosed() throws IOException {
+    private final void checkClosed() throws IOException {
         if (closed) {
             throw new EOFException("Cannot write to the stream any more it has already been closed");
         }
     }
 
-    /**
-     * @return the amount free space in the buffer
-     */
-    private int availableBufferToWrite() {
-        return buffer.length - count;
-    }
 }