| 1 | |
package org.jaudiotagger.tag.id3; |
| 2 | |
|
| 3 | |
import org.jaudiotagger.audio.generic.Utils; |
| 4 | |
import org.jaudiotagger.tag.TagField; |
| 5 | |
import org.jaudiotagger.tag.TagTextField; |
| 6 | |
|
| 7 | |
import java.io.UnsupportedEncodingException; |
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
public class ID3v1TagField implements TagTextField |
| 17 | |
{ |
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
private boolean common; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
private String content; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
private String id; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
public ID3v1TagField(byte[] raw) throws UnsupportedEncodingException |
| 45 | 0 | { |
| 46 | 0 | String field = new String(raw, "ISO-8859-1"); |
| 47 | |
|
| 48 | 0 | int i = field.indexOf("="); |
| 49 | 0 | if (i == -1) |
| 50 | |
{ |
| 51 | |
|
| 52 | 0 | this.id = "ERRONEOUS"; |
| 53 | 0 | this.content = field; |
| 54 | |
} |
| 55 | |
else |
| 56 | |
{ |
| 57 | 0 | this.id = field.substring(0, i).toUpperCase(); |
| 58 | 0 | if (field.length() > i) |
| 59 | |
{ |
| 60 | 0 | this.content = field.substring(i + 1); |
| 61 | |
} |
| 62 | |
else |
| 63 | |
{ |
| 64 | |
|
| 65 | 0 | this.content = ""; |
| 66 | |
} |
| 67 | |
} |
| 68 | 0 | checkCommon(); |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
public ID3v1TagField(String fieldId, String fieldContent) |
| 78 | 336 | { |
| 79 | 336 | this.id = fieldId.toUpperCase(); |
| 80 | 336 | this.content = fieldContent; |
| 81 | 336 | checkCommon(); |
| 82 | 336 | } |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
private void checkCommon() |
| 90 | |
{ |
| 91 | 336 | this.common = id.equals(ID3v1FieldKey.TITLE.name()) || id.equals(ID3v1FieldKey.ALBUM.name()) || id.equals(ID3v1FieldKey.ARTIST.name()) || id.equals(ID3v1FieldKey.GENRE.name()) || id.equals(ID3v1FieldKey.YEAR.name()) || id.equals(ID3v1FieldKey.COMMENT.name()) || id.equals(ID3v1FieldKey.TRACK.name()); |
| 92 | 336 | } |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
protected void copy(byte[] src, byte[] dst, int dstOffset) |
| 104 | |
{ |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | 0 | System.arraycopy(src, 0, dst, dstOffset, src.length); |
| 112 | 0 | } |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
public void copyContent(TagField field) |
| 118 | |
{ |
| 119 | 0 | if (field instanceof TagTextField) |
| 120 | |
{ |
| 121 | 0 | this.content = ((TagTextField) field).getContent(); |
| 122 | |
} |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
public String getContent() |
| 129 | |
{ |
| 130 | 336 | return content; |
| 131 | |
} |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
public String getEncoding() |
| 137 | |
{ |
| 138 | 0 | return "ISO-8859-1"; |
| 139 | |
} |
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
public String getId() |
| 145 | |
{ |
| 146 | 224 | return this.id; |
| 147 | |
} |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public byte[] getRawContent() throws UnsupportedEncodingException |
| 153 | |
{ |
| 154 | 0 | byte[] size = new byte[4]; |
| 155 | 0 | byte[] idBytes = this.id.getBytes("ISO-8859-1"); |
| 156 | 0 | byte[] contentBytes = Utils.getDefaultBytes(this.content, "ISO-8859-1"); |
| 157 | 0 | byte[] b = new byte[4 + idBytes.length + 1 + contentBytes.length]; |
| 158 | |
|
| 159 | 0 | int length = idBytes.length + 1 + contentBytes.length; |
| 160 | 0 | size[3] = (byte) ((length & 0xFF000000) >> 24); |
| 161 | 0 | size[2] = (byte) ((length & 0x00FF0000) >> 16); |
| 162 | 0 | size[1] = (byte) ((length & 0x0000FF00) >> 8); |
| 163 | 0 | size[0] = (byte) (length & 0x000000FF); |
| 164 | |
|
| 165 | 0 | int offset = 0; |
| 166 | 0 | copy(size, b, offset); |
| 167 | 0 | offset += 4; |
| 168 | 0 | copy(idBytes, b, offset); |
| 169 | 0 | offset += idBytes.length; |
| 170 | 0 | b[offset] = (byte) 0x3D; |
| 171 | 0 | offset++; |
| 172 | 0 | copy(contentBytes, b, offset); |
| 173 | |
|
| 174 | 0 | return b; |
| 175 | |
} |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
public boolean isBinary() |
| 181 | |
{ |
| 182 | 0 | return false; |
| 183 | |
} |
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
public void isBinary(boolean b) |
| 189 | |
{ |
| 190 | |
|
| 191 | 0 | } |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
public boolean isCommon() |
| 197 | |
{ |
| 198 | 0 | return common; |
| 199 | |
} |
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
public boolean isEmpty() |
| 205 | |
{ |
| 206 | 0 | return this.content.equals(""); |
| 207 | |
} |
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
public void setContent(String s) |
| 213 | |
{ |
| 214 | 0 | this.content = s; |
| 215 | 0 | } |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
public void setEncoding(String s) |
| 221 | |
{ |
| 222 | |
|
| 223 | 0 | } |
| 224 | |
|
| 225 | |
public String toString() |
| 226 | |
{ |
| 227 | 144 | return getContent(); |
| 228 | |
} |
| 229 | |
} |