Coverage Report - org.jaudiotagger.audio.asf.data.ContentDescription
 
Classes in this File Line Coverage Branch Coverage Complexity
ContentDescription
88%
64/73
85%
17/20
1.625
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2004-2005 Christian Laireiter <liree@web.de>
 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.audio.asf.data;
 20  
 
 21  
 import org.jaudiotagger.audio.asf.io.WriteableChunk;
 22  
 import org.jaudiotagger.audio.asf.util.Utils;
 23  
 
 24  
 import java.io.IOException;
 25  
 import java.io.OutputStream;
 26  
 import java.math.BigInteger;
 27  
 
 28  
 /**
 29  
  * This class represents the data of a chunk which contains title, author,
 30  
  * copyright, description and the rating of the file. <br>
 31  
  * It is optional within ASF files. But if, exists only once.
 32  
  *
 33  
  * @author Christian Laireiter
 34  
  */
 35  
 public class ContentDescription extends Chunk implements WriteableChunk
 36  
 {
 37  
     /**
 38  
      * File artist.
 39  
      */
 40  72
     private String author = null;
 41  
 
 42  
     /**
 43  
      * File copyright.
 44  
      */
 45  72
     private String copyRight = null;
 46  
 
 47  
     /**
 48  
      * File comment.
 49  
      */
 50  72
     private String description = null;
 51  
 
 52  
     /**
 53  
      * File rating.
 54  
      */
 55  72
     private String rating = null;
 56  
 
 57  
     /**
 58  
      * File title.
 59  
      */
 60  72
     private String title = null;
 61  
 
 62  
     /**
 63  
      * Creates an instance. <br>
 64  
      */
 65  
     public ContentDescription()
 66  
     {
 67  17
         this(0, BigInteger.valueOf(0));
 68  17
     }
 69  
 
 70  
     /**
 71  
      * Creates an instance.
 72  
      *
 73  
      * @param pos      Position of content description within file or stream
 74  
      * @param chunkLen Length of content description.
 75  
      */
 76  
     public ContentDescription(long pos, BigInteger chunkLen)
 77  
     {
 78  72
         super(GUID.GUID_CONTENTDESCRIPTION, pos, chunkLen);
 79  72
     }
 80  
 
 81  
     /**
 82  
      * @return Returns the author.
 83  
      */
 84  
     public String getAuthor()
 85  
     {
 86  103
         if (author == null)
 87  
         {
 88  0
             return "";
 89  
         }
 90  103
         return author;
 91  
     }
 92  
 
 93  
     /**
 94  
      * @return Returns the comment.
 95  
      */
 96  
     public String getComment()
 97  
     {
 98  103
         if (description == null)
 99  
         {
 100  3
             return "";
 101  
         }
 102  100
         return description;
 103  
     }
 104  
 
 105  
     /**
 106  
      * @return Returns the copyRight.
 107  
      */
 108  
     public String getCopyRight()
 109  
     {
 110  103
         if (copyRight == null)
 111  
         {
 112  3
             return "";
 113  
         }
 114  100
         return copyRight;
 115  
     }
 116  
 
 117  
     /**
 118  
      * {@inheritDoc}
 119  
      */
 120  
     public long getCurrentAsfChunkSize()
 121  
     {
 122  34
         long result = 44; // GUID + UINT64 for size + 5 times string length (each
 123  
         // 2 bytes) + 5 times zero term char (2 bytes each).
 124  34
         result += getAuthor().length() * 2; // UTF-16LE
 125  34
         result += getComment().length() * 2;
 126  34
         result += getRating().length() * 2;
 127  34
         result += getTitle().length() * 2;
 128  34
         result += getCopyRight().length() * 2;
 129  34
         return result;
 130  
     }
 131  
 
 132  
     /**
 133  
      * @return returns the rating.
 134  
      */
 135  
     public String getRating()
 136  
     {
 137  103
         if (rating == null)
 138  
         {
 139  16
             return "";
 140  
         }
 141  87
         return rating;
 142  
     }
 143  
 
 144  
     /**
 145  
      * @return Returns the title.
 146  
      */
 147  
     public String getTitle()
 148  
     {
 149  103
         if (title == null)
 150  
         {
 151  0
             return "";
 152  
         }
 153  103
         return title;
 154  
     }
 155  
 
 156  
     /**
 157  
      * {@inheritDoc}
 158  
      */
 159  
     public boolean isEmpty()
 160  
     {
 161  24
         return Utils.isBlank(author) && Utils.isBlank(copyRight) && Utils.isBlank(description) && Utils.isBlank(rating) && Utils
 162  
                         .isBlank(title);
 163  
     }
 164  
 
 165  
     /**
 166  
      * 
 167  
      * {@inheritDoc}
 168  
      */
 169  
     public String prettyPrint(final String prefix)
 170  
     {
 171  0
         StringBuffer result = new StringBuffer(super.prettyPrint(prefix));
 172  0
         result.append(prefix + "  |->Title      : " + getTitle() + Utils.LINE_SEPARATOR);
 173  0
         result.append(prefix + "  |->Author     : " + getAuthor() + Utils.LINE_SEPARATOR);
 174  0
         result.append(prefix + "  |->Copyright  : " + getCopyRight() + Utils.LINE_SEPARATOR);
 175  0
         result.append(prefix + "  |->Description: " + getComment() + Utils.LINE_SEPARATOR);
 176  0
         result.append(prefix + "  |->Rating     :" + getRating() + Utils.LINE_SEPARATOR);
 177  0
         return result.toString();
 178  
     }
 179  
 
 180  
     /**
 181  
      * @param fileAuthor The author to set.
 182  
      * @throws IllegalArgumentException If "UTF-16LE"-byte-representation would take more than 65535
 183  
      *                                  bytes.
 184  
      */
 185  
     public void setAuthor(String fileAuthor) throws IllegalArgumentException
 186  
     {
 187  72
         Utils.checkStringLengthNullSafe(fileAuthor);
 188  72
         this.author = fileAuthor;
 189  72
     }
 190  
 
 191  
     /**
 192  
      * @param tagComment The comment to set.
 193  
      * @throws IllegalArgumentException If "UTF-16LE"-byte-representation would take more than 65535
 194  
      *                                  bytes.
 195  
      */
 196  
     public void setComment(String tagComment) throws IllegalArgumentException
 197  
     {
 198  69
         Utils.checkStringLengthNullSafe(tagComment);
 199  69
         this.description = tagComment;
 200  69
     }
 201  
 
 202  
     /**
 203  
      * @param cpright The copyRight to set.
 204  
      * @throws IllegalArgumentException If "UTF-16LE"-byte-representation would take more than 65535
 205  
      *                                  bytes.
 206  
      */
 207  
     public void setCopyRight(String cpright) throws IllegalArgumentException
 208  
     {
 209  69
         Utils.checkStringLengthNullSafe(cpright);
 210  69
         this.copyRight = cpright;
 211  69
     }
 212  
 
 213  
     /**
 214  
      * @param ratingText The rating to be set.
 215  
      * @throws IllegalArgumentException If "UTF-16LE"-byte-representation would take more than 65535
 216  
      *                                  bytes.
 217  
      */
 218  
     public void setRating(String ratingText) throws IllegalArgumentException
 219  
     {
 220  48
         Utils.checkStringLengthNullSafe(ratingText);
 221  48
         this.rating = ratingText;
 222  48
     }
 223  
 
 224  
     /**
 225  
      * @param songTitle The title to set.
 226  
      * @throws IllegalArgumentException If "UTF-16LE"-byte-representation would take more than 65535
 227  
      *                                  bytes.
 228  
      */
 229  
     public void setTitle(String songTitle) throws IllegalArgumentException
 230  
     {
 231  72
         Utils.checkStringLengthNullSafe(songTitle);
 232  72
         this.title = songTitle;
 233  72
     }
 234  
 
 235  
     /**
 236  
      * {@inheritDoc}
 237  
      */
 238  
     public long writeInto(OutputStream out) throws IOException
 239  
     {
 240  17
         long chunkSize = getCurrentAsfChunkSize();
 241  
 
 242  17
         out.write(this.getGuid().getBytes());
 243  17
         Utils.writeUINT64(getCurrentAsfChunkSize(), out);
 244  
         // write the sizes of the string representations plus 2 bytes zero term
 245  
         // character
 246  17
         Utils.writeUINT16(getTitle().length() * 2 + 2, out);
 247  17
         Utils.writeUINT16(getAuthor().length() * 2 + 2, out);
 248  17
         Utils.writeUINT16(getCopyRight().length() * 2 + 2, out);
 249  17
         Utils.writeUINT16(getComment().length() * 2 + 2, out);
 250  17
         Utils.writeUINT16(getRating().length() * 2 + 2, out);
 251  
         // write the Strings
 252  17
         out.write(Utils.getBytes(getTitle(), AsfHeader.ASF_CHARSET));
 253  17
         out.write(AsfHeader.ZERO_TERM);
 254  17
         out.write(Utils.getBytes(getAuthor(), AsfHeader.ASF_CHARSET));
 255  17
         out.write(AsfHeader.ZERO_TERM);
 256  17
         out.write(Utils.getBytes(getCopyRight(), AsfHeader.ASF_CHARSET));
 257  17
         out.write(AsfHeader.ZERO_TERM);
 258  17
         out.write(Utils.getBytes(getComment(), AsfHeader.ASF_CHARSET));
 259  17
         out.write(AsfHeader.ZERO_TERM);
 260  17
         out.write(Utils.getBytes(getRating(), AsfHeader.ASF_CHARSET));
 261  17
         out.write(AsfHeader.ZERO_TERM);
 262  17
         return chunkSize;
 263  
     }
 264  
 }