ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r306847 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java
Date Thu, 06 Oct 2005 19:12:53 GMT
Author: mbenson
Date: Thu Oct  6 12:12:49 2005
New Revision: 306847

URL: http://svn.apache.org/viewcvs?rev=306847&view=rev
Log:
implement TODO of configurable buffer size.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java?rev=306847&r1=306846&r2=306847&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java Thu Oct  6 12:12:49
2005
@@ -28,9 +28,6 @@
  */
 public class StreamPumper implements Runnable {
 
-    // TODO: make SIZE an instance variable.
-
-    private static final int SIZE = 128;
     private InputStream is;
     private OutputStream os;
     private volatile boolean finish;
@@ -38,6 +35,8 @@
     private boolean closeWhenExhausted;
     private boolean autoflush = false;
     private Exception exception = null;
+    private int bufferSize = 128;
+    private boolean started = false;
 
     /**
      * Create a new stream pumper.
@@ -79,10 +78,13 @@
      * Terminates as soon as the input stream is closed or an error occurs.
      */
     public void run() {
+        synchronized (this) {
+            started = true;
+        }
         finished = false;
         finish = false;
 
-        final byte[] buf = new byte[SIZE];
+        final byte[] buf = new byte[bufferSize];
 
         int length;
         try {
@@ -129,6 +131,27 @@
         while (!isFinished()) {
             wait();
         }
+    }
+
+    /**
+     * Set the size in bytes of the read buffer.
+     * @param bufferSize the buffer size to use.
+     * @throws IllegalStateException if the StreamPumper is already running.
+     */
+    public synchronized void setBufferSize(int bufferSize) {
+        if (started) {
+            throw new IllegalStateException(
+                "Cannot set buffer size on a running StreamPumper");
+        }
+        this.bufferSize = bufferSize;
+    }
+
+    /**
+     * Get the size in bytes of the read buffer.
+     * @return the int size of the read buffer.
+     */
+    public synchronized int getBufferSize() {
+        return bufferSize;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message