Coverage Report - org.jaudiotagger.audio.asf.io.AsfExtHeaderReader
 
Classes in this File Line Coverage Branch Coverage Complexity
AsfExtHeaderReader
100%
12/12
50%
5/10
1.25
 
 1  
 package org.jaudiotagger.audio.asf.io;
 2  
 
 3  
 import org.jaudiotagger.audio.asf.data.AsfExtendedHeader;
 4  
 import org.jaudiotagger.audio.asf.data.GUID;
 5  
 import org.jaudiotagger.audio.asf.util.Utils;
 6  
 
 7  
 import java.io.IOException;
 8  
 import java.io.InputStream;
 9  
 import java.math.BigInteger;
 10  
 import java.util.List;
 11  
 
 12  
 /**
 13  
  * This reader reads an ASF header extension object from an {@link InputStream}
 14  
  * and creates an {@link AsfExtendedHeader} object.<br>
 15  
  * 
 16  
  * @author Christian Laireiter
 17  
  */
 18  415
 public class AsfExtHeaderReader extends ChunkContainerReader<AsfExtendedHeader> {
 19  
 
 20  
     /**
 21  
      * The GUID this reader {@linkplain #getApplyingIds() applies to}
 22  
      */
 23  4
     private final static GUID[] APPLYING = { GUID.GUID_HEADER_EXTENSION };
 24  
 
 25  
     /**
 26  
      * Creates a reader instance, which only utilizes the given list of chunk
 27  
      * readers.<br>
 28  
      * 
 29  
      * @param toRegister
 30  
      *            List of {@link ChunkReader} class instances, which are to be
 31  
      *            utilized by the instance.
 32  
      * @param readChunkOnce
 33  
      *            if <code>true</code>, each chunk type (identified by chunk
 34  
      *            GUID) will handled only once, if a reader is available, other
 35  
      *            chunks will be discarded.
 36  
      */
 37  
     public AsfExtHeaderReader(
 38  
             final List<Class<? extends ChunkReader>> toRegister,
 39  
             final boolean readChunkOnce) {
 40  12
         super(toRegister, readChunkOnce);
 41  12
     }
 42  
 
 43  
     /**
 44  
      * {@inheritDoc}
 45  
      */
 46  
     public boolean canFail() {
 47  411
         return false;
 48  
     }
 49  
 
 50  
     /**
 51  
      * {@inheritDoc}
 52  
      */
 53  
     @Override
 54  
     protected AsfExtendedHeader createContainer(final long streamPosition,
 55  
             final BigInteger chunkLength, final InputStream stream)
 56  
             throws IOException {
 57  411
         Utils.readGUID(stream); // First reserved field (should be a specific
 58  
         // GUID.
 59  411
         Utils.readUINT16(stream); // Second reserved field (should always be 6)
 60  411
         final long extensionSize = Utils.readUINT32(stream);
 61  411
         assert extensionSize == 0 || extensionSize >= 24;
 62  411
         assert chunkLength.subtract(BigInteger.valueOf(46)).longValue() == extensionSize;
 63  411
         return new AsfExtendedHeader(streamPosition, chunkLength);
 64  
     }
 65  
     
 66  
     /**
 67  
      * {@inheritDoc}
 68  
      */
 69  
     public GUID[] getApplyingIds() {
 70  423
         return APPLYING.clone();
 71  
     }
 72  
 
 73  
 }