Coverage Report - org.jaudiotagger.tag.datatype.ID3v2LyricLine
 
Classes in this File Line Coverage Branch Coverage Complexity
ID3v2LyricLine
0%
0/41
0%
0/18
2.091
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: ID3v2LyricLine.java 836 2009-11-12 15:44:07Z paultaylor $
 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 = 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))
 95  
         {
 96  0
             return false;
 97  
         }
 98  
 
 99  0
         ID3v2LyricLine object = (ID3v2LyricLine) obj;
 100  
 
 101  0
         if (!this.text.equals(object.text))
 102  
         {
 103  0
             return false;
 104  
         }
 105  
 
 106  0
         return this.timeStamp == object.timeStamp && super.equals(obj);
 107  
 
 108  
     }
 109  
 
 110  
     /**
 111  
      * @param arr
 112  
      * @param offset
 113  
      * @throws NullPointerException
 114  
      * @throws IndexOutOfBoundsException
 115  
      */
 116  
     public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
 117  
     {
 118  0
         if (arr == null)
 119  
         {
 120  0
             throw new NullPointerException("Byte array is null");
 121  
         }
 122  
 
 123  0
         if ((offset < 0) || (offset >= arr.length))
 124  
         {
 125  0
             throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length);
 126  
         }
 127  
 
 128  
         //offset += ();
 129  0
         text = Utils.getString(arr, offset, arr.length - offset - 4, "ISO-8859-1");
 130  
 
 131  
         //text = text.substring(0, text.length() - 5);
 132  0
         timeStamp = 0;
 133  
 
 134  0
         for (int i = arr.length - 4; i < arr.length; i++)
 135  
         {
 136  0
             timeStamp <<= 8;
 137  0
             timeStamp += arr[i];
 138  
         }
 139  0
     }
 140  
 
 141  
     /**
 142  
      * @return
 143  
      */
 144  
     public String toString()
 145  
     {
 146  0
         return timeStamp + " " + text;
 147  
     }
 148  
 
 149  
     /**
 150  
      * @return
 151  
      */
 152  
     public byte[] writeByteArray()
 153  
     {
 154  
         int i;
 155  0
         byte[] arr = new byte[getSize()];
 156  
 
 157  0
         for (i = 0; i < text.length(); i++)
 158  
         {
 159  0
             arr[i] = (byte) text.charAt(i);
 160  
         }
 161  
 
 162  0
         arr[i++] = 0;
 163  0
         arr[i++] = (byte) ((timeStamp & 0xFF000000) >> 24);
 164  0
         arr[i++] = (byte) ((timeStamp & 0x00FF0000) >> 16);
 165  0
         arr[i++] = (byte) ((timeStamp & 0x0000FF00) >> 8);
 166  0
         arr[i++] = (byte) (timeStamp & 0x000000FF);
 167  
 
 168  0
         return arr;
 169  
     }
 170  
 }