| 1 | |
package org.jaudiotagger.tag.mp4.field; |
| 2 | |
|
| 3 | |
import org.jaudiotagger.audio.generic.Utils; |
| 4 | |
import org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader; |
| 5 | |
import org.jaudiotagger.tag.TagField; |
| 6 | |
import org.jaudiotagger.tag.mp4.Mp4TagField; |
| 7 | |
|
| 8 | |
import java.io.ByteArrayOutputStream; |
| 9 | |
import java.io.IOException; |
| 10 | |
import java.io.UnsupportedEncodingException; |
| 11 | |
import java.nio.ByteBuffer; |
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
public class Mp4TagRawBinaryField extends Mp4TagField |
| 21 | |
{ |
| 22 | |
protected int dataSize; |
| 23 | |
protected byte[] dataBytes; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public Mp4TagRawBinaryField(Mp4BoxHeader header, ByteBuffer raw) throws UnsupportedEncodingException |
| 35 | |
{ |
| 36 | 8 | super(header.getId()); |
| 37 | 8 | dataSize = header.getDataLength(); |
| 38 | 8 | build(raw); |
| 39 | 8 | } |
| 40 | |
|
| 41 | |
public Mp4FieldType getFieldType() |
| 42 | |
{ |
| 43 | 0 | return Mp4FieldType.IMPLICIT; |
| 44 | |
} |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
protected byte[] getDataBytes() throws UnsupportedEncodingException |
| 54 | |
{ |
| 55 | 0 | return dataBytes; |
| 56 | |
} |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
protected void build(ByteBuffer raw) |
| 67 | |
{ |
| 68 | |
|
| 69 | 8 | this.dataBytes = new byte[dataSize]; |
| 70 | 1456 | for (int i = 0; i < dataBytes.length; i++) |
| 71 | |
{ |
| 72 | 1448 | this.dataBytes[i] = raw.get(); |
| 73 | |
} |
| 74 | 8 | } |
| 75 | |
|
| 76 | |
public boolean isBinary() |
| 77 | |
{ |
| 78 | 0 | return true; |
| 79 | |
} |
| 80 | |
|
| 81 | |
public boolean isEmpty() |
| 82 | |
{ |
| 83 | 0 | return this.dataBytes.length == 0; |
| 84 | |
} |
| 85 | |
|
| 86 | |
public int getDataSize() |
| 87 | |
{ |
| 88 | 0 | return dataSize; |
| 89 | |
|
| 90 | |
} |
| 91 | |
|
| 92 | |
public byte[] getData() |
| 93 | |
{ |
| 94 | 0 | return this.dataBytes; |
| 95 | |
} |
| 96 | |
|
| 97 | |
public void setData(byte[] d) |
| 98 | |
{ |
| 99 | 0 | this.dataBytes = d; |
| 100 | 0 | } |
| 101 | |
|
| 102 | |
public void copyContent(TagField field) |
| 103 | |
{ |
| 104 | 0 | throw new UnsupportedOperationException("not done"); |
| 105 | |
} |
| 106 | |
|
| 107 | |
public byte[] getRawContent() throws UnsupportedEncodingException |
| 108 | |
{ |
| 109 | 4 | logger.fine("Getting Raw data for:" + getId()); |
| 110 | |
try |
| 111 | |
{ |
| 112 | 4 | ByteArrayOutputStream outerbaos = new ByteArrayOutputStream(); |
| 113 | 4 | outerbaos.write(Utils.getSizeBEInt32(Mp4BoxHeader.HEADER_LENGTH + dataSize)); |
| 114 | 4 | outerbaos.write(Utils.getDefaultBytes(getId(), "ISO-8859-1")); |
| 115 | 4 | outerbaos.write(dataBytes); |
| 116 | 4 | System.out.println("SIZE" + outerbaos.size()); |
| 117 | 4 | return outerbaos.toByteArray(); |
| 118 | |
} |
| 119 | 0 | catch (IOException ioe) |
| 120 | |
{ |
| 121 | |
|
| 122 | 0 | throw new RuntimeException(ioe); |
| 123 | |
} |
| 124 | |
} |
| 125 | |
|
| 126 | |
} |