You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2002/12/07 21:31:08 UTC

cvs commit: jakarta-commons-sandbox/io/src/java/org/apache/commons/io/output CountingOutputStream.java TeeOutputStream.java

bayard      2002/12/07 12:31:08

  Modified:    io/src/java/org/apache/commons/io IOUtil.java
               io/src/java/org/apache/commons/io/output
                        CountingOutputStream.java TeeOutputStream.java
  Added:       io/src/java/org/apache/commons/io ProxyInputStream.java
                        ProxyOutputStream.java
  Removed:     io/src/java/org/apache/commons/io StreamUtils.java
  Log:
  StreamUtils is redundant, all the functionality is in IOUtils.
  ProxyStreams are needed as FilterStream's are not 'honest' about
  calling the same method that was called upon themselves. I find this
  a pain to code to.
  CountingOutput/TeeOutput both changed to be Proxy's.
  
  Revision  Changes    Path
  1.2       +5 -5      jakarta-commons-sandbox/io/src/java/org/apache/commons/io/IOUtil.java
  
  Index: IOUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/IOUtil.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IOUtil.java	8 Jul 2002 22:14:46 -0000	1.1
  +++ IOUtil.java	7 Dec 2002 20:31:07 -0000	1.2
  @@ -168,7 +168,7 @@
        */
       public static void shutdownReader( final Reader input )
       {
  -        if( null == input )
  +        if( input == null )
           {
               return;
           }
  @@ -190,7 +190,7 @@
        */
       public static void shutdownWriter( final Writer output )
       {
  -        if( null == output )
  +        if( output == null )
           {
               return;
           }
  @@ -211,7 +211,7 @@
        */
       public static void shutdownStream( final OutputStream output )
       {
  -        if( null == output )
  +        if( output == null )
           {
               return;
           }
  @@ -232,7 +232,7 @@
        */
       public static void shutdownStream( final InputStream input )
       {
  -        if( null == input )
  +        if( input == null )
           {
               return;
           }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/ProxyInputStream.java
  
  Index: ProxyInputStream.java
  ===================================================================
  package org.apache.commons.io;
  
  import java.io.FilterInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  
  // A Proxy stream which acts as expected, that is it passes the method 
  // calls on to the proxied stream and doesn't change which methods are 
  // being called. It is a Filter stream to increase reusability.
  public abstract class ProxyInputStream extends FilterInputStream {
  
      private InputStream proxy;
  
      public ProxyInputStream(InputStream proxy) {
          super(proxy);
          this.proxy = proxy;
      }
  
      public int read() throws IOException {
          return this.proxy.read();
      }
  
      public int read(byte[] bts) throws IOException {
          return this.proxy.read(bts);
      }
  
      public int read(byte[] bts, int st, int end) throws IOException {
          return this.proxy.read(bts, st, end);
      }
  
      public long skip(long ln) throws IOException {
          return this.proxy.skip(ln);
      }
  
      public int available() throws IOException {
          return this.proxy.available();
      }
  
      public void close() throws IOException {
          this.proxy.close();
      }
  
      public synchronized void mark(int idx) {
          this.proxy.mark(idx);
      }
  
      public synchronized void reset() throws IOException {
          this.proxy.reset();
      }
  
      public boolean markSupported() {
          return this.proxy.markSupported();
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/ProxyOutputStream.java
  
  Index: ProxyOutputStream.java
  ===================================================================
  package org.apache.commons.io;
  
  import java.io.IOException;
  import java.io.FilterOutputStream;
  import java.io.OutputStream;
  
  // A Proxy stream which acts as expected, that is it passes the method 
  // calls on to the proxied stream and doesn't change which methods are 
  // being called. It is a Filter stream to increase reusability.
  public class ProxyOutputStream extends FilterOutputStream {
  
      private OutputStream proxy;
  
      public ProxyOutputStream(OutputStream proxy) {
          super(proxy);
          this.proxy = proxy;
      }
  
      public void write(int idx) throws IOException {
          this.proxy.write(idx);
      }
  
      public void write(byte[] bts) throws IOException {
          this.proxy.write(bts);
      }
  
      public void write(byte[] bts, int st, int end) throws IOException {
          this.proxy.write(bts, st, end);
      }
  
      public void flush() throws IOException {
          this.proxy.flush();
      }
  
      public void close() throws IOException {
          this.proxy.close();
      }
  
  }
  
  
  
  1.2       +3 -3      jakarta-commons-sandbox/io/src/java/org/apache/commons/io/output/CountingOutputStream.java
  
  Index: CountingOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/output/CountingOutputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CountingOutputStream.java	11 Nov 2002 19:34:02 -0000	1.1
  +++ CountingOutputStream.java	7 Dec 2002 20:31:08 -0000	1.2
  @@ -56,7 +56,7 @@
   
   import java.io.IOException;
   import java.io.OutputStream;
  -import java.io.FilterOutputStream;
  +import org.apache.commons.io.ProxyOutputStream;
   
   /**
    * Used in debugging, it counts the number of bytes that pass 
  @@ -65,7 +65,7 @@
    * @author <a href="mailto:bayard@apache.org">Henri Yandell</a>
    * @version $Id$
    */
  -public class CountingOutputStream extends FilterOutputStream {
  +public class CountingOutputStream extends ProxyOutputStream {
   
       private int count;
   
  
  
  
  1.2       +10 -5     jakarta-commons-sandbox/io/src/java/org/apache/commons/io/output/TeeOutputStream.java
  
  Index: TeeOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/output/TeeOutputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TeeOutputStream.java	11 Nov 2002 19:34:02 -0000	1.1
  +++ TeeOutputStream.java	7 Dec 2002 20:31:08 -0000	1.2
  @@ -56,7 +56,7 @@
   
   import java.io.IOException;
   import java.io.OutputStream;
  -import java.io.FilterOutputStream;
  +import org.apache.commons.io.ProxyOutputStream;
   
   /**
    * Classic splitter of OutputStream. Named after the unix 'tee' 
  @@ -66,7 +66,7 @@
    * @author <a href="mailto:bayard@apache.org">Henri Yandell</a>
    * @version $Id$
    */
  -public class TeeOutputStream extends FilterOutputStream {
  +public class TeeOutputStream extends ProxyOutputStream {
   
       protected OutputStream branch;
   
  @@ -75,6 +75,11 @@
           this.branch = branch;
       }
   
  +    public synchronized void write(byte[] b) throws IOException {
  +        super.write(b);
  +        this.branch.write(b);
  +    }
  +
       public synchronized void write(byte[] b, int off, int len) throws IOException {
           super.write(b, off, len);
           this.branch.write(b, off, len);
  @@ -87,12 +92,12 @@
   
       public void flush() throws IOException {
           super.flush();
  -        branch.flush();
  +        this.branch.flush();
       }
   
       public void close() throws IOException {
           super.close();
  -        branch.close();
  +        this.branch.close();
       }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>