Coverage Report - org.jaudiotagger.tag.mp4.field.Mp4TagTextNumberField
 
Classes in this File Line Coverage Branch Coverage Complexity
Mp4TagTextNumberField
74%
17/23
50%
2/4
0
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2003-2005 Rapha�l Slinckx <raphael@slinckx.net>
 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.tag.mp4.field;
 20  
 
 21  
 import org.jaudiotagger.audio.generic.Utils;
 22  
 import org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader;
 23  
 import org.jaudiotagger.tag.TagField;
 24  
 import org.jaudiotagger.tag.mp4.atom.Mp4DataBox;
 25  
 
 26  
 import java.io.ByteArrayOutputStream;
 27  
 import java.io.IOException;
 28  
 import java.io.UnsupportedEncodingException;
 29  
 import java.nio.ByteBuffer;
 30  
 import java.util.List;
 31  
 
 32  
 /**
 33  
  * Represents simple text field that contains an array of number,
 34  
  * <p/>
 35  
  * <p>But reads the data content as an arry of 16 bit unsigned numbers
 36  
  */
 37  
 public class Mp4TagTextNumberField extends Mp4TagTextField
 38  
 {
 39  
     public static final int NUMBER_LENGTH = 2;
 40  
 
 41  
     //Holds the numbers decoded
 42  
     protected List<Short> numbers;
 43  
 
 44  
     /**
 45  
      * Create a new number, already parsed in subclasses
 46  
      *
 47  
      * @param id
 48  
      * @param numberArray
 49  
      */
 50  
     public Mp4TagTextNumberField(String id, String numberArray)
 51  
     {
 52  19
         super(id, numberArray);
 53  19
     }
 54  
 
 55  
     public Mp4TagTextNumberField(String id, ByteBuffer data) throws UnsupportedEncodingException
 56  
     {
 57  170
         super(id, data);
 58  170
     }
 59  
 
 60  
     /**
 61  
      * Recreate the raw data content from the list of numbers
 62  
      *
 63  
      * @return
 64  
      */
 65  
     protected byte[] getDataBytes()
 66  
     {
 67  87
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 68  87
         for (Short number : numbers)
 69  
         {
 70  
             try
 71  
             {
 72  238
                 baos.write(Utils.getSizeBEInt16(number));
 73  
             }
 74  0
             catch (IOException e)
 75  
             {
 76  
                 //This should never happen because we are not writing to file at this point.
 77  0
                 throw new RuntimeException(e);
 78  238
             }
 79  
         }
 80  87
         return baos.toByteArray();
 81  
     }
 82  
 
 83  
     public void copyContent(TagField field)
 84  
     {
 85  0
         if (field instanceof Mp4TagTextNumberField)
 86  
         {
 87  0
             this.content = ((Mp4TagTextNumberField) field).getContent();
 88  0
             this.numbers = ((Mp4TagTextNumberField) field).getNumbers();
 89  
         }
 90  0
     }
 91  
 
 92  
     /**
 93  
      * @return type numeric
 94  
      */
 95  
     public Mp4FieldType getFieldType()
 96  
     {
 97  87
         return Mp4FieldType.NUMERIC;
 98  
     }
 99  
 
 100  
     protected void build(ByteBuffer data) throws UnsupportedEncodingException
 101  
     {
 102  
         //Data actually contains a 'Data' Box so process data using this
 103  7
         Mp4BoxHeader header = new Mp4BoxHeader(data);
 104  7
         Mp4DataBox databox = new Mp4DataBox(header, data);
 105  7
         dataSize = header.getDataLength();
 106  7
         content = databox.getContent();
 107  7
         numbers = databox.getNumbers();
 108  7
     }
 109  
 
 110  
     /**
 111  
      * @return the individual numbers making up this field
 112  
      */
 113  
     public List<Short> getNumbers()
 114  
     {
 115  112
         return numbers;
 116  
     }
 117  
 }