Coverage Report - org.jaudiotagger.audio.asf.data.StreamBitratePropertiesChunk
 
Classes in this File Line Coverage Branch Coverage Complexity
StreamBitratePropertiesChunk
44%
7/16
0%
0/4
0
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2004-2005 Christian Laireiter <liree@web.de>
 4  
  * 
 5  
  * This library is free software; you can redistribute it and/or
 6  
  * modify it under the terms of the GNU Lesser General Public
 7  
  * License as published by the Free Software Foundation; either
 8  
  * version 2.1 of the License, or (at your option) any later version.
 9  
  *  
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  * Lesser General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU Lesser General Public
 16  
  * License along with this library; if not, write to the Free Software
 17  
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.jaudiotagger.audio.asf.data;
 20  
 
 21  
 import java.math.BigInteger;
 22  
 import java.util.ArrayList;
 23  
 
 24  
 import org.jaudiotagger.audio.asf.util.Utils;
 25  
 
 26  
 /**
 27  
  * This class represents the "Stream Bitrate Properties" chunk of an ASF media
 28  
  * file. <br>
 29  
  * It is optional, but contains useful information about the streams bitrate.<br>
 30  
  *
 31  
  * @author Christian Laireiter
 32  
  */
 33  
 public class StreamBitratePropertiesChunk extends Chunk
 34  
 {
 35  
 
 36  
     /**
 37  
      * For each call of {@link #addBitrateRecord(int,long)} an {@link Long}
 38  
      * object is appended, which represents the average bitrate.
 39  
      */
 40  
     private final ArrayList<Long> bitRates;
 41  
 
 42  
     /**
 43  
      * For each call of {@link #addBitrateRecord(int,long)} an {@link Integer}
 44  
      * object is appended, which represents the stream-number.
 45  
      */
 46  
     private final ArrayList<Integer> streamNumbers;
 47  
 
 48  
     /**
 49  
      * Creates an instance.
 50  
      *
 51  
      * @param chunkLen Length of current chunk.
 52  
      */
 53  
     public StreamBitratePropertiesChunk(BigInteger chunkLen)
 54  
     {
 55  16
         super(GUID.GUID_STREAM_BITRATE_PROPERTIES, chunkLen);
 56  16
         this.bitRates = new ArrayList<Long>();
 57  16
         this.streamNumbers = new ArrayList<Integer>();
 58  16
     }
 59  
 
 60  
     /**
 61  
      * Adds the public values of a stream-record.
 62  
      *
 63  
      * @param streamNum      The number of the referred stream.
 64  
      * @param averageBitrate Its average bitrate.
 65  
      */
 66  
     public void addBitrateRecord(int streamNum, long averageBitrate)
 67  
     {
 68  16
         this.streamNumbers.add(new Integer(streamNum));
 69  16
         this.bitRates.add(new Long(averageBitrate));
 70  16
     }
 71  
 
 72  
     /**
 73  
      * Returns the average bitrate of the given stream.<br>
 74  
      *
 75  
      * @param streamNumber Number of the stream whose bitrate to determine.
 76  
      * @return The average bitrate of the numbered stream. <code>-1</code> if
 77  
      *         no information was given.
 78  
      */
 79  
     public long getAvgBitrate(int streamNumber)
 80  
     {
 81  0
         Integer seach = new Integer(streamNumber);
 82  0
         int index = streamNumbers.indexOf(seach);
 83  0
         if (index != -1)
 84  
         {
 85  0
             return bitRates.get(index).longValue();
 86  
         }
 87  0
         return -1;
 88  
     }
 89  
 
 90  
     /**
 91  
      * (overridden)
 92  
      *
 93  
      * @see org.jaudiotagger.audio.asf.data.Chunk#prettyPrint(String)
 94  
      */
 95  
     public String prettyPrint(final String prefix)
 96  
     {
 97  0
         StringBuffer result = new StringBuffer(super.prettyPrint(prefix));
 98  0
         for (int i = 0; i < bitRates.size(); i++)
 99  
         {
 100  0
             result
 101  
                             .append(prefix + "  |-> Stream no. \"" + streamNumbers.get(i)
 102  
                     + "\" has an average bitrate of \"" + bitRates.get(i)
 103  
                     + "\"" + Utils.LINE_SEPARATOR);
 104  
         }
 105  0
         return result.toString();
 106  
     }
 107  
 
 108  
 }