Coverage Report - org.jaudiotagger.audio.asf.io.CountingOutputstream
 
Classes in this File Line Coverage Branch Coverage Complexity
CountingOutputstream
50%
10/20
50%
2/4
1
 
 1  
 package org.jaudiotagger.audio.asf.io;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.io.OutputStream;
 5  
 
 6  
 /**
 7  
  * This output stream wraps around another {@link OutputStream} and delegates
 8  
  * the write calls.<br>
 9  
  * Additionally all written bytes are counted and available by
 10  
  * {@link #getCount()}.
 11  
  * 
 12  
  * @author Christian Laireiter
 13  
  */
 14  4
 public class CountingOutputstream extends OutputStream {
 15  
 
 16  
     /**
 17  
      * Stores the amount of bytes written.
 18  
      */
 19  697
     private long count = 0;
 20  
 
 21  
     /**
 22  
      * The stream to forward the write calls.
 23  
      */
 24  
     private final OutputStream wrapped;
 25  
 
 26  
     /**
 27  
      * Creates an instance which will delegate the write calls to the given
 28  
      * output stream.
 29  
      * 
 30  
      * @param outputStream
 31  
      *            stream to wrap.
 32  
      */
 33  
     public CountingOutputstream(final OutputStream outputStream) {
 34  697
         super();
 35  697
         assert outputStream != null;
 36  697
         this.wrapped = outputStream;
 37  697
     }
 38  
 
 39  
     /**
 40  
      * {@inheritDoc}
 41  
      */
 42  
     @Override
 43  
     public void close() throws IOException {
 44  0
         this.wrapped.close();
 45  0
     }
 46  
 
 47  
     /**
 48  
      * {@inheritDoc}
 49  
      */
 50  
     @Override
 51  
     public void flush() throws IOException {
 52  0
         this.wrapped.flush();
 53  0
     }
 54  
 
 55  
     /**
 56  
      * @return the count
 57  
      */
 58  
     public long getCount() {
 59  216
         return this.count;
 60  
     }
 61  
 
 62  
     /**
 63  
      * {@inheritDoc}
 64  
      */
 65  
     @Override
 66  
     public void write(final byte[] bytes) throws IOException {
 67  17048
         this.wrapped.write(bytes);
 68  17048
         this.count += bytes.length;
 69  17048
     }
 70  
 
 71  
     /**
 72  
      * {@inheritDoc}
 73  
      */
 74  
     @Override
 75  
     public void write(final byte[] bytes, final int off, final int len)
 76  
             throws IOException {
 77  0
         this.wrapped.write(bytes, off, len);
 78  0
         this.count += len;
 79  0
     }
 80  
 
 81  
     /**
 82  
      * {@inheritDoc}
 83  
      */
 84  
     @Override
 85  
     public void write(final int toWrite) throws IOException {
 86  0
         this.wrapped.write(toWrite);
 87  0
         this.count++;
 88  0
     }
 89  
 
 90  
 }