Coverage Report - org.jaudiotagger.tag.datatype.Lyrics3Image
 
Classes in this File Line Coverage Branch Coverage Complexity
Lyrics3Image
0%
0/68
0%
0/32
2.533
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: Lyrics3Image.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 Lyrics3Image extends AbstractDataType
 31  
 {
 32  
     /**
 33  
      *
 34  
      */
 35  0
     private Lyrics3TimeStamp time = null;
 36  
 
 37  
     /**
 38  
      *
 39  
      */
 40  0
     private String description = "";
 41  
 
 42  
     /**
 43  
      *
 44  
      */
 45  0
     private String filename = "";
 46  
 
 47  
     /**
 48  
      * Creates a new ObjectLyrics3Image datatype.
 49  
      *
 50  
      * @param identifier
 51  
      * @param frameBody
 52  
      */
 53  
     public Lyrics3Image(String identifier, AbstractTagFrameBody frameBody)
 54  
     {
 55  0
         super(identifier, frameBody);
 56  0
     }
 57  
 
 58  
     public Lyrics3Image(Lyrics3Image copy)
 59  
     {
 60  0
         super(copy);
 61  0
         this.time = new Lyrics3TimeStamp(copy.time);
 62  0
         this.description = copy.description;
 63  0
         this.filename = copy.filename;
 64  0
     }
 65  
 
 66  
     /**
 67  
      * @param description
 68  
      */
 69  
     public void setDescription(String description)
 70  
     {
 71  0
         this.description = description;
 72  0
     }
 73  
 
 74  
     /**
 75  
      * @return
 76  
      */
 77  
     public String getDescription()
 78  
     {
 79  0
         return this.description;
 80  
     }
 81  
 
 82  
     /**
 83  
      * @param filename
 84  
      */
 85  
     public void setFilename(String filename)
 86  
     {
 87  0
         this.filename = filename;
 88  0
     }
 89  
 
 90  
     /**
 91  
      * @return
 92  
      */
 93  
     public String getFilename()
 94  
     {
 95  0
         return this.filename;
 96  
     }
 97  
 
 98  
     /**
 99  
      * @return
 100  
      */
 101  
     public int getSize()
 102  
     {
 103  
         int size;
 104  
 
 105  0
         size = filename.length() + 2 + description.length() + 2;
 106  
 
 107  0
         if (time != null)
 108  
         {
 109  0
             size += time.getSize();
 110  
         }
 111  
 
 112  0
         return size;
 113  
     }
 114  
 
 115  
     /**
 116  
      * @param time
 117  
      */
 118  
     public void setTimeStamp(Lyrics3TimeStamp time)
 119  
     {
 120  0
         this.time = time;
 121  0
     }
 122  
 
 123  
     /**
 124  
      * @return
 125  
      */
 126  
     public Lyrics3TimeStamp getTimeStamp()
 127  
     {
 128  0
         return this.time;
 129  
     }
 130  
 
 131  
     /**
 132  
      * @param obj
 133  
      * @return
 134  
      */
 135  
     public boolean equals(Object obj)
 136  
     {
 137  0
         if (!(obj instanceof Lyrics3Image))
 138  
         {
 139  0
             return false;
 140  
         }
 141  
 
 142  0
         Lyrics3Image object = (Lyrics3Image) obj;
 143  
 
 144  0
         if (!this.description.equals(object.description))
 145  
         {
 146  0
             return false;
 147  
         }
 148  
 
 149  0
         if (!this.filename.equals(object.filename))
 150  
         {
 151  0
             return false;
 152  
         }
 153  
 
 154  0
         if (this.time == null)
 155  
         {
 156  0
             if (object.time != null)
 157  
             {
 158  0
                 return false;
 159  
             }
 160  
         }
 161  
         else
 162  
         {
 163  0
             if (!this.time.equals(object.time))
 164  
             {
 165  0
                 return false;
 166  
             }
 167  
         }
 168  
 
 169  0
         return super.equals(obj);
 170  
     }
 171  
 
 172  
     /**
 173  
      * @param imageString
 174  
      * @param offset
 175  
      * @throws NullPointerException
 176  
      * @throws IndexOutOfBoundsException
 177  
      */
 178  
     public void readString(String imageString, int offset)
 179  
     {
 180  0
         if (imageString == null)
 181  
         {
 182  0
             throw new NullPointerException("Image string is null");
 183  
         }
 184  
 
 185  0
         if ((offset < 0) || (offset >= imageString.length()))
 186  
         {
 187  0
             throw new IndexOutOfBoundsException("Offset to image string is out of bounds: offset = " + offset + ", string.length()" + imageString.length());
 188  
         }
 189  
 
 190  0
         if (imageString != null)
 191  
         {
 192  
             String timestamp;
 193  
             int delim;
 194  
 
 195  0
             delim = imageString.indexOf("||", offset);
 196  0
             filename = imageString.substring(offset, delim);
 197  
 
 198  0
             offset = delim + 2;
 199  0
             delim = imageString.indexOf("||", offset);
 200  0
             description = imageString.substring(offset, delim);
 201  
 
 202  0
             offset = delim + 2;
 203  0
             timestamp = imageString.substring(offset);
 204  
 
 205  0
             if (timestamp.length() == 7)
 206  
             {
 207  0
                 time = new Lyrics3TimeStamp("Time Stamp");
 208  0
                 time.readString(timestamp);
 209  
             }
 210  
         }
 211  0
     }
 212  
 
 213  
     /**
 214  
      * @return
 215  
      */
 216  
     public String toString()
 217  
     {
 218  
         String str;
 219  0
         str = "filename = " + filename + ", description = " + description;
 220  
 
 221  0
         if (time != null)
 222  
         {
 223  0
             str += (", timestamp = " + time.toString());
 224  
         }
 225  
 
 226  0
         return str + "\n";
 227  
     }
 228  
 
 229  
     /**
 230  
      * @return
 231  
      */
 232  
     public String writeString()
 233  
     {
 234  
         String str;
 235  
 
 236  0
         if (filename == null)
 237  
         {
 238  0
             str = "||";
 239  
         }
 240  
         else
 241  
         {
 242  0
             str = filename + "||";
 243  
         }
 244  
 
 245  0
         if (description == null)
 246  
         {
 247  0
             str += "||";
 248  
         }
 249  
         else
 250  
         {
 251  0
             str += (description + "||");
 252  
         }
 253  
 
 254  0
         if (time != null)
 255  
         {
 256  0
             str += time.writeString();
 257  
         }
 258  
 
 259  0
         return str;
 260  
     }
 261  
 
 262  
     public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
 263  
     {
 264  0
         readString(arr.toString(), offset);
 265  0
     }
 266  
 
 267  
     public byte[] writeByteArray()
 268  
     {
 269  0
         return Utils.getDefaultBytes(writeString(), "ISO-8859-1");
 270  
     }
 271  
 
 272  
 }