Coverage Report - org.jaudiotagger.audio.asf.io.RandomAccessFileInputstream
 
Classes in this File Line Coverage Branch Coverage Complexity
RandomAccessFileInputstream
71%
10/14
50%
3/6
2.25
 
 1  
 package org.jaudiotagger.audio.asf.io;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.io.InputStream;
 5  
 import java.io.RandomAccessFile;
 6  
 
 7  
 /**
 8  
  * Wraps a {@link RandomAccessFile} into an {@link InputStream}.<br>
 9  
  * 
 10  
  * @author Christian Laireiter
 11  
  */
 12  
 public final class RandomAccessFileInputstream extends InputStream {
 13  
 
 14  
     /**
 15  
      * The file access to read from.<br>
 16  
      */
 17  
     private final RandomAccessFile source;
 18  
 
 19  
     /**
 20  
      * Creates an instance that will provide {@link InputStream} functionality
 21  
      * on the given {@link RandomAccessFile} by delegating calls.<br>
 22  
      * 
 23  
      * @param file
 24  
      *            The file to read.
 25  
      */
 26  
     public RandomAccessFileInputstream(final RandomAccessFile file) {
 27  278
         super();
 28  278
         if (file == null) {
 29  0
             throw new IllegalArgumentException("null");
 30  
         }
 31  278
         this.source = file;
 32  278
     }
 33  
 
 34  
     /**
 35  
      * {@inheritDoc}
 36  
      */
 37  
     @Override
 38  
     public int read() throws IOException {
 39  39956
         return this.source.read();
 40  
     }
 41  
 
 42  
     /**
 43  
      * {@inheritDoc}
 44  
      */
 45  
     @Override
 46  
     public int read(final byte[] buffer, final int off, final int len)
 47  
             throws IOException {
 48  16956
         return this.source.read(buffer, off, len);
 49  
     }
 50  
 
 51  
     /**
 52  
      * {@inheritDoc}
 53  
      */
 54  
     @Override
 55  
     public long skip(final long amount) throws IOException {
 56  256
         if (amount < 0) {
 57  0
             throw new IllegalArgumentException("invalid negative value");
 58  
         }
 59  256
         long left = amount;
 60  256
         while (left > Integer.MAX_VALUE) {
 61  0
             this.source.skipBytes(Integer.MAX_VALUE);
 62  0
             left -= Integer.MAX_VALUE;
 63  
         }
 64  256
         return this.source.skipBytes((int) left);
 65  
     }
 66  
 
 67  
 }