commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject cvs commit: jakarta-commons/io/src/test/org/apache/commons/io/output CountingOutputStreamTest.java
Date Sun, 13 Jun 2004 05:35:44 GMT
bayard      2004/06/12 22:35:44

  Modified:    io/src/java/org/apache/commons/io/input
                        CountingInputStream.java
               io/src/java/org/apache/commons/io/output
                        CountingOutputStream.java
               io/src/test/org/apache/commons/io/input
                        CountingInputStreamTest.java
               io/src/test/org/apache/commons/io/output
                        CountingOutputStreamTest.java
  Log:
  reset feature added to counting classes as requested by Lars Beuster
  
  Revision  Changes    Path
  1.9       +12 -1     jakarta-commons/io/src/java/org/apache/commons/io/input/CountingInputStream.java
  
  Index: CountingInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/java/org/apache/commons/io/input/CountingInputStream.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CountingInputStream.java	23 Feb 2004 04:38:52 -0000	1.8
  +++ CountingInputStream.java	13 Jun 2004 05:35:44 -0000	1.9
  @@ -78,4 +78,15 @@
           return this.count;
       }
   
  +    /** 
  +      * Set the count back to 0. 
  +      *
  +      * @return the count previous to resetting.
  +      */
  +    public synchronized int resetCount() {
  +        int tmp = this.count;
  +        this.count = 0;
  +        return tmp;
  +    }
  +
   }
  
  
  
  1.6       +11 -1     jakarta-commons/io/src/java/org/apache/commons/io/output/CountingOutputStream.java
  
  Index: CountingOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/java/org/apache/commons/io/output/CountingOutputStream.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CountingOutputStream.java	23 Feb 2004 04:40:29 -0000	1.5
  +++ CountingOutputStream.java	13 Jun 2004 05:35:44 -0000	1.6
  @@ -63,4 +63,14 @@
           return this.count;
       }
   
  +    /** 
  +      * Set the count back to 0. 
  +      *
  +      * @return the count previous to resetting.
  +      */
  +    public synchronized int resetCount() {
  +        int tmp = this.count;
  +        this.count = 0;
  +        return tmp;
  +    }
   }
  
  
  
  1.5       +16 -0     jakarta-commons/io/src/test/org/apache/commons/io/input/CountingInputStreamTest.java
  
  Index: CountingInputStreamTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/input/CountingInputStreamTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CountingInputStreamTest.java	23 Feb 2004 05:02:25 -0000	1.4
  +++ CountingInputStreamTest.java	13 Jun 2004 05:35:44 -0000	1.5
  @@ -62,5 +62,21 @@
           String textResult = new String(result).trim();
           assertEquals(textResult, text);
       }
  +
  +    public void testResetting() throws Exception {
  +        String text = "A piece of text";
  +        byte[] bytes = text.getBytes();
  +        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
  +        CountingInputStream cis = new CountingInputStream(bais);
  +
  +        byte[] result = new byte[bytes.length];
  +
  +        int found = cis.read(result, 0, 5);
  +        assertEquals( found, cis.getCount() );
  +
  +        int count = cis.resetCount();
  +        found = cis.read(result, 6, 5);
  +        assertEquals( found, cis.getCount() );
  +    }
   }
   
  
  
  
  1.3       +12 -6     jakarta-commons/io/src/test/org/apache/commons/io/output/CountingOutputStreamTest.java
  
  Index: CountingOutputStreamTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/output/CountingOutputStreamTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CountingOutputStreamTest.java	23 Feb 2004 05:02:25 -0000	1.2
  +++ CountingOutputStreamTest.java	13 Jun 2004 05:35:44 -0000	1.3
  @@ -59,15 +59,21 @@
           cos.write(array, 5, 5);
           assertByteArrayEquals("CountingOutputStream.write(byte[], int, int)", baos.toByteArray(),
0, 35);
           assertEquals("CountingOutputStream.getCount()", cos.getCount(), 35);
  +
  +        int count = cos.resetCount();
  +        assertEquals("CountingOutputStream.resetCount()", count, 35);
  +
  +        for(int i = 0; i < 10; i++) {
  +            cos.write(i);
  +        }
  +        assertByteArrayEquals("CountingOutputStream.write(int)", baos.toByteArray(), 35,
45);
  +        assertEquals("CountingOutputStream.getCount()", cos.getCount(), 10);
  +
       }
   
       private void assertByteArrayEquals(String msg, byte[] array, int start, int end) {
  -        assertEquals(msg+": array size mismatch", end-start,
  -                array.length );
  -
           for (int i = start; i < end; i++) {
  -            assertEquals(msg+": array[ " + i + "] mismatch", array[i],
  -                    i);
  +            assertEquals(msg+": array[" + i + "] mismatch", array[i], i-start);
           }
       }
   
  
  
  

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


Mime
View raw message