| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 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 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public class ContentDescription extends Chunk implements WriteableChunk |
| 36 | |
{ |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 72 | private String author = null; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | 72 | private String copyRight = null; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | 72 | private String description = null; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | 72 | private String rating = null; |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | 72 | private String title = null; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public ContentDescription() |
| 66 | |
{ |
| 67 | 17 | this(0, BigInteger.valueOf(0)); |
| 68 | 17 | } |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public ContentDescription(long pos, BigInteger chunkLen) |
| 77 | |
{ |
| 78 | 72 | super(GUID.GUID_CONTENTDESCRIPTION, pos, chunkLen); |
| 79 | 72 | } |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
public String getAuthor() |
| 85 | |
{ |
| 86 | 103 | if (author == null) |
| 87 | |
{ |
| 88 | 0 | return ""; |
| 89 | |
} |
| 90 | 103 | return author; |
| 91 | |
} |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
public String getComment() |
| 97 | |
{ |
| 98 | 103 | if (description == null) |
| 99 | |
{ |
| 100 | 3 | return ""; |
| 101 | |
} |
| 102 | 100 | return description; |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public String getCopyRight() |
| 109 | |
{ |
| 110 | 103 | if (copyRight == null) |
| 111 | |
{ |
| 112 | 3 | return ""; |
| 113 | |
} |
| 114 | 100 | return copyRight; |
| 115 | |
} |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
public long getCurrentAsfChunkSize() |
| 121 | |
{ |
| 122 | 34 | long result = 44; |
| 123 | |
|
| 124 | 34 | result += getAuthor().length() * 2; |
| 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 | |
|
| 134 | |
|
| 135 | |
public String getRating() |
| 136 | |
{ |
| 137 | 103 | if (rating == null) |
| 138 | |
{ |
| 139 | 16 | return ""; |
| 140 | |
} |
| 141 | 87 | return rating; |
| 142 | |
} |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
public String getTitle() |
| 148 | |
{ |
| 149 | 103 | if (title == null) |
| 150 | |
{ |
| 151 | 0 | return ""; |
| 152 | |
} |
| 153 | 103 | return title; |
| 154 | |
} |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 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 | |
|
| 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 | |
|
| 182 | |
|
| 183 | |
|
| 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 | |
|
| 193 | |
|
| 194 | |
|
| 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 | |
|
| 204 | |
|
| 205 | |
|
| 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 | |
|
| 215 | |
|
| 216 | |
|
| 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 | |
|
| 226 | |
|
| 227 | |
|
| 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 | |
|
| 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 | |
|
| 245 | |
|
| 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 | |
|
| 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 | |
} |