1 | package org.farng.mp3.lyrics3; |
2 | |
3 | import java.io.IOException; |
4 | import java.io.RandomAccessFile; |
5 | |
6 | /** |
7 | * This is used if the field identifier is not recognized. the contents of the frame are read as a byte stream and kept |
8 | * so they can be saved when the file is written again |
9 | * |
10 | * @author Eric Farng |
11 | * @version $Revision: 1.4 $ |
12 | */ |
13 | public class FieldBodyUnsupported extends AbstractLyrics3v2FieldBody { |
14 | |
15 | private byte[] value = null; |
16 | |
17 | /** |
18 | * Creates a new FieldBodyUnsupported object. |
19 | */ |
20 | public FieldBodyUnsupported() { |
21 | super(); |
22 | } |
23 | |
24 | /** |
25 | * Creates a new FieldBodyUnsupported object. |
26 | */ |
27 | public FieldBodyUnsupported(final FieldBodyUnsupported copyObject) { |
28 | super(copyObject); |
29 | this.value = (byte[]) copyObject.value.clone(); |
30 | } |
31 | |
32 | /** |
33 | * Creates a new FieldBodyUnsupported object. |
34 | */ |
35 | public FieldBodyUnsupported(final byte[] value) { |
36 | this.value = value; |
37 | } |
38 | |
39 | /** |
40 | * Creates a new FieldBodyUnsupported object. |
41 | */ |
42 | public FieldBodyUnsupported(final RandomAccessFile file) throws java.io.IOException { |
43 | this.read(file); |
44 | } |
45 | |
46 | public String getIdentifier() { |
47 | return "ZZZ"; |
48 | } |
49 | |
50 | public boolean isSubsetOf(final Object object) { |
51 | if ((object instanceof FieldBodyUnsupported) == false) { |
52 | return false; |
53 | } |
54 | final FieldBodyUnsupported fieldBodyUnsupported = (FieldBodyUnsupported) object; |
55 | final String subset = new String(this.value); |
56 | final String superset = new String(fieldBodyUnsupported.value); |
57 | if (superset.indexOf(subset) < 0) { |
58 | return false; |
59 | } |
60 | return super.isSubsetOf(object); |
61 | } |
62 | |
63 | public boolean equals(final Object obj) { |
64 | if ((obj instanceof FieldBodyUnsupported) == false) { |
65 | return false; |
66 | } |
67 | final FieldBodyUnsupported fieldBodyUnsupported = (FieldBodyUnsupported) obj; |
68 | if (java.util.Arrays.equals(this.value, fieldBodyUnsupported.value) == false) { |
69 | return false; |
70 | } |
71 | return super.equals(obj); |
72 | } |
73 | |
74 | protected void setupObjectList() { |
75 | // throw new UnsupportedOperationException(); |
76 | } |
77 | |
78 | public void read(final RandomAccessFile file) throws IOException { |
79 | final int size; |
80 | final byte[] buffer = new byte[5]; |
81 | |
82 | // read the 5 character size |
83 | file.read(buffer, 0, 5); |
84 | size = Integer.parseInt(new String(buffer, 0, 5)); |
85 | this.value = new byte[size]; |
86 | |
87 | // read the SIZE length description |
88 | file.read(this.value); |
89 | } |
90 | |
91 | public String toString() { |
92 | return getIdentifier() + " : " + (new String(this.value)); |
93 | } |
94 | |
95 | public void write(final RandomAccessFile file) throws IOException { |
96 | int offset = 0; |
97 | final String str; |
98 | final byte[] buffer = new byte[5]; |
99 | str = Integer.toString(this.value.length); |
100 | for (int i = 0; i < (5 - str.length()); i++) { |
101 | buffer[i] = (byte) '0'; |
102 | } |
103 | offset += (5 - str.length()); |
104 | for (int i = 0; i < str.length(); i++) { |
105 | buffer[i + offset] = (byte) str.charAt(i); |
106 | } |
107 | file.write(buffer); |
108 | file.write(this.value); |
109 | } |
110 | } |