Coverage Report - org.jaudiotagger.audio.asf.io.FullRequestInputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
FullRequestInputStream
77%
17/22
58%
7/12
0
 
 1  
 package org.jaudiotagger.audio.asf.io;
 2  
 
 3  
 import java.io.FilterInputStream;
 4  
 import java.io.IOException;
 5  
 import java.io.InputStream;
 6  
 
 7  
 /**
 8  
  * This implementation repeatedly reads from the wrapped input stream until the requested amount
 9  
  * of bytes are read.<br> 
 10  
  * 
 11  
  * @author Christian Laireiter
 12  
  */
 13  
 public class FullRequestInputStream extends FilterInputStream {
 14  
 
 15  
     /**
 16  
      * Creates an instance.
 17  
      * @param source stream to read from.
 18  
      */
 19  
         public FullRequestInputStream(InputStream source) {
 20  64
                 super(source);
 21  64
         }
 22  
 
 23  
         /**
 24  
      * {@inheritDoc}
 25  
      */
 26  
         @Override
 27  
         public int read(byte[] b) throws IOException {
 28  0
                 return read(b, 0, b.length);
 29  
         }
 30  
 
 31  
         /**
 32  
      * {@inheritDoc}
 33  
      */
 34  
         @Override
 35  
         public int read(byte[] b, int off, int len) throws IOException {
 36  3656
                 int totalRead = 0;
 37  3656
                 int read = -1;
 38  7322
                 while (totalRead < len) {
 39  3666
                         read = super.read(b, off + totalRead, len - totalRead);
 40  3666
                         if (read >= 0) {
 41  3666
                                 totalRead += read;
 42  
                         }
 43  3666
                         if (read == -1)
 44  
             {
 45  0
                 throw new IOException((len - totalRead) + " more bytes expected.");
 46  
             }
 47  
                 }
 48  3656
                 return totalRead;
 49  
         }
 50  
 
 51  
         /**
 52  
      * {@inheritDoc}
 53  
      */
 54  
         @Override
 55  
         public long skip(long n) throws IOException {
 56  648
                 long skipped = 0;
 57  648
                 int zeroSkipCnt = 0;
 58  
                 long currSkipped;
 59  1300
                 while (skipped < n) {
 60  652
                         currSkipped = super.skip(n - skipped);
 61  652
                         if (currSkipped == 0) {
 62  0
                                 zeroSkipCnt++;
 63  0
                                 if (zeroSkipCnt == 2) {
 64  
                                         // If the skip value exceeds streams size, this and the
 65  
                                         // number is extremely large, this can lead to a very long
 66  
                                         // running loop.
 67  0
                                         return skipped;
 68  
                                 }
 69  
                         }
 70  652
                         skipped += currSkipped;
 71  
                 }
 72  648
                 return skipped;
 73  
         }
 74  
 
 75  
 }