1 | package org.farng.mp3.object; |
2 | |
3 | /** |
4 | * ID3v2 and Lyrics3v2 tags have individual fields <code>AbstractMP3Fragment</code>s Then each fragment is broken down |
5 | * in to individual <code>AbstractMP3Object</code>s |
6 | * |
7 | * @author Eric Farng |
8 | * @version $Revision: 1.5 $ |
9 | */ |
10 | public class ObjectStringNullTerminated extends AbstractMP3Object { |
11 | |
12 | /** |
13 | * Creates a new ObjectStringNullTerminated object. |
14 | */ |
15 | public ObjectStringNullTerminated(final String identifier) { |
16 | this.identifier = identifier; |
17 | } |
18 | |
19 | /** |
20 | * Creates a new ObjectStringNullTerminated object. |
21 | */ |
22 | public ObjectStringNullTerminated(final ObjectStringNullTerminated object) { |
23 | super(object); |
24 | } |
25 | |
26 | public int getSize() { |
27 | int len = 0; |
28 | if (this.value != null) { |
29 | len = ((String) this.value).length() + 1; |
30 | } |
31 | return len; |
32 | } |
33 | |
34 | public boolean equals(final Object obj) { |
35 | if (obj instanceof ObjectStringNullTerminated == false) { |
36 | return false; |
37 | } |
38 | return super.equals(obj); |
39 | } |
40 | |
41 | public void readString(final String str, final int offset) { |
42 | if (str == null) { |
43 | throw new NullPointerException("String is null"); |
44 | } |
45 | if ((offset < 0) || (offset >= str.length())) { |
46 | throw new IndexOutOfBoundsException("Offset to String is out of bounds: offset = " + |
47 | offset + |
48 | ", string.length()" + |
49 | str.length()); |
50 | } |
51 | final int delim = str.indexOf(0, offset); |
52 | if (delim >= 0) { |
53 | this.value = str.substring(offset, delim); |
54 | } else { |
55 | this.value = str.substring(offset); |
56 | } |
57 | } |
58 | |
59 | public String toString() { |
60 | return (String) this.value; |
61 | } |
62 | |
63 | public String writeString() { |
64 | String string = ""; |
65 | if (this.value != null) { |
66 | string = this.value.toString() + (char) 0; |
67 | } |
68 | return string; |
69 | } |
70 | } |