Coverage Report - org.jaudiotagger.tag.datatype.ID3v2LyricLine
 
Classes in this File Line Coverage Branch Coverage Complexity
ID3v2LyricLine
0%
0/43
0%
0/16
2.091
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: ID3v2LyricLine.java,v 1.8 2008/07/21 10:45:41 paultaylor Exp $
 6  
  *
 7  
  *  MusicTag Copyright (C)2003,2004
 8  
  *
 9  
  *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 10  
  *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 11  
  *  or (at your option) any later version.
 12  
  *
 13  
  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 14  
  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 15  
  *  See the GNU Lesser General Public License for more details.
 16  
  *
 17  
  *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 18  
  *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 19  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 20  
  *
 21  
  * Description:
 22  
  *
 23  
  */
 24  
 package org.jaudiotagger.tag.datatype;
 25  
 
 26  
 import org.jaudiotagger.audio.generic.Utils;
 27  
 import org.jaudiotagger.tag.InvalidDataTypeException;
 28  
 import org.jaudiotagger.tag.id3.AbstractTagFrameBody;
 29  
 
 30  
 public class ID3v2LyricLine extends AbstractDataType
 31  
 {
 32  
     /**
 33  
      *
 34  
      */
 35  0
     String text = "";
 36  
 
 37  
     /**
 38  
      *
 39  
      */
 40  0
     long timeStamp = 0;
 41  
 
 42  
     public ID3v2LyricLine(String identifier, AbstractTagFrameBody frameBody)
 43  
     {
 44  0
         super(identifier, frameBody);
 45  0
     }
 46  
 
 47  
     public ID3v2LyricLine(ID3v2LyricLine copy)
 48  
     {
 49  0
         super(copy);
 50  0
         this.text = new String(copy.text);
 51  0
         this.timeStamp = copy.timeStamp;
 52  0
     }
 53  
 
 54  
     /**
 55  
      * @return
 56  
      */
 57  
     public int getSize()
 58  
     {
 59  0
         return text.length() + 1 + 4;
 60  
     }
 61  
 
 62  
     public void setText(String text)
 63  
     {
 64  0
         this.text = text;
 65  0
     }
 66  
 
 67  
     /**
 68  
      * @return
 69  
      */
 70  
     public String getText()
 71  
     {
 72  0
         return text;
 73  
     }
 74  
 
 75  
     public void setTimeStamp(long timeStamp)
 76  
     {
 77  0
         this.timeStamp = timeStamp;
 78  0
     }
 79  
 
 80  
     /**
 81  
      * @return
 82  
      */
 83  
     public long getTimeStamp()
 84  
     {
 85  0
         return timeStamp;
 86  
     }
 87  
 
 88  
     /**
 89  
      * @param obj
 90  
      * @return
 91  
      */
 92  
     public boolean equals(Object obj)
 93  
     {
 94  0
         if ((obj instanceof ID3v2LyricLine) == false)
 95  
         {
 96  0
             return false;
 97  
         }
 98  
 
 99  0
         ID3v2LyricLine object = (ID3v2LyricLine) obj;
 100  
 
 101  0
         if (this.text.equals(object.text) == false)
 102  
         {
 103  0
             return false;
 104  
         }
 105  
 
 106  0
         if (this.timeStamp != object.timeStamp)
 107  
         {
 108  0
             return false;
 109  
         }
 110  
 
 111  0
         return super.equals(obj);
 112  
     }
 113  
 
 114  
     /**
 115  
      * @param arr
 116  
      * @param offset
 117  
      * @throws NullPointerException
 118  
      * @throws IndexOutOfBoundsException
 119  
      */
 120  
     public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
 121  
     {
 122  0
         if (arr == null)
 123  
         {
 124  0
             throw new NullPointerException("Byte array is null");
 125  
         }
 126  
 
 127  0
         if ((offset < 0) || (offset >= arr.length))
 128  
         {
 129  0
             throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length);
 130  
         }
 131  
 
 132  
         //offset += ();
 133  0
         text = Utils.getString(arr, offset, arr.length - offset - 4, "ISO-8859-1");
 134  
 
 135  
         //text = text.substring(0, text.length() - 5);
 136  0
         timeStamp = 0;
 137  
 
 138  0
         for (int i = arr.length - 4; i < arr.length; i++)
 139  
         {
 140  0
             timeStamp <<= 8;
 141  0
             timeStamp += arr[i];
 142  
         }
 143  0
     }
 144  
 
 145  
     /**
 146  
      * @return
 147  
      */
 148  
     public String toString()
 149  
     {
 150  0
         return timeStamp + " " + text;
 151  
     }
 152  
 
 153  
     /**
 154  
      * @return
 155  
      */
 156  
     public byte[] writeByteArray()
 157  
     {
 158  
         int i;
 159  0
         byte[] arr = new byte[getSize()];
 160  
 
 161  0
         for (i = 0; i < text.length(); i++)
 162  
         {
 163  0
             arr[i] = (byte) text.charAt(i);
 164  
         }
 165  
 
 166  0
         arr[i++] = 0;
 167  0
         arr[i++] = (byte) ((timeStamp & 0xFF000000) >> 24);
 168  0
         arr[i++] = (byte) ((timeStamp & 0x00FF0000) >> 16);
 169  0
         arr[i++] = (byte) ((timeStamp & 0x0000FF00) >> 8);
 170  0
         arr[i++] = (byte) (timeStamp & 0x000000FF);
 171  
 
 172  0
         return arr;
 173  
     }
 174  
 }