bayard      2002/10/18 15:01:33

  Modified:    io/src/java/org/apache/commons/io CountingOutputStream.java
  Added:       io/src/java/org/apache/commons/io CountingInputStream.java
  Log:
  Count an InputStream too. Typo fixed in OutputStream.
  
  Need to decide how much to increase a count by when an int is read or written.
  
  Revision  Changes    Path
  1.2       +3 -2      
jakarta-commons-sandbox/io/src/java/org/apache/commons/io/CountingOutputStream.java
  
  Index: CountingOutputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/CountingOutputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CountingOutputStream.java 23 Feb 2002 04:29:53 -0000      1.1
  +++ CountingOutputStream.java 18 Oct 2002 22:01:33 -0000      1.2
  @@ -59,7 +59,7 @@
   import java.io.FilterOutputStream;
   
   /**
  - * Used in debugging, it counts the number of byts that pass 
  + * Used in debugging, it counts the number of bytes that pass 
    * through it.
    *
    * @author <a href="mailto:bayard@;apache.org">Henri Yandell</a>
  @@ -83,6 +83,7 @@
           super.write(b, off, len);
       }
   
  +    /// TODO: Decide if this should increment by 2, or 4, or 1 etc.
       public void write(int b) throws IOException {
           count++;
           super.write(b);
  
  
  
  1.1                  
jakarta-commons-sandbox/io/src/java/org/apache/commons/io/CountingInputStream.java
  
  Index: CountingInputStream.java
  ===================================================================
  package org.apache.commons.io;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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/>.
   */
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.FilterInputStream;
  
  /**
   * Used in debugging, it counts the number of bytes that pass 
   * through it.
   *
   * @author <a href="mailto:bayard@;apache.org">Henri Yandell</a>
   * @version $Id: CountingInputStream.java,v 1.1 2002/10/18 22:01:33 bayard Exp $
   */
  public class CountingInputStream extends FilterInputStream {
  
      private int count;
  
      public CountingInputStream( InputStream in ) {
          super(in);
      }
  
      public int read(byte[] b) throws IOException {
          count += b.length;
          return super.read(b);
      }
  
      public int read(byte[] b, int off, int len) throws IOException {
          count += len;
          return super.read(b, off, len);
      }
  
      /// TODO: Decide if this should increment by 2, or 4, or 1 etc.
      public int read() throws IOException {
          count++;
          return super.read();
      }
  
      /**
       * The number of bytes that have passed through this stream.
       */
      public int getCount() {
          return this.count;
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>

Reply via email to