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