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