| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.jaudiotagger.tag.mp4.field; |
| 20 | |
|
| 21 | |
import org.jaudiotagger.audio.generic.Utils; |
| 22 | |
import org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader; |
| 23 | |
import org.jaudiotagger.tag.TagField; |
| 24 | |
import org.jaudiotagger.tag.mp4.atom.Mp4DataBox; |
| 25 | |
|
| 26 | |
import java.io.ByteArrayOutputStream; |
| 27 | |
import java.io.IOException; |
| 28 | |
import java.io.UnsupportedEncodingException; |
| 29 | |
import java.nio.ByteBuffer; |
| 30 | |
import java.util.List; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public class Mp4TagTextNumberField extends Mp4TagTextField |
| 38 | |
{ |
| 39 | |
public static final int NUMBER_LENGTH = 2; |
| 40 | |
|
| 41 | |
|
| 42 | |
protected List<Short> numbers; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public Mp4TagTextNumberField(String id, String numberArray) |
| 51 | |
{ |
| 52 | 120 | super(id, numberArray); |
| 53 | 120 | } |
| 54 | |
|
| 55 | |
public Mp4TagTextNumberField(String id, ByteBuffer data) throws UnsupportedEncodingException |
| 56 | |
{ |
| 57 | 542 | super(id, data); |
| 58 | 542 | } |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
protected byte[] getDataBytes() |
| 66 | |
{ |
| 67 | 274 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 68 | 274 | for (Short number : numbers) |
| 69 | |
{ |
| 70 | |
try |
| 71 | |
{ |
| 72 | 793 | baos.write(Utils.getSizeBEInt16(number)); |
| 73 | |
} |
| 74 | 0 | catch (IOException e) |
| 75 | |
{ |
| 76 | |
|
| 77 | 0 | throw new RuntimeException(e); |
| 78 | 793 | } |
| 79 | |
} |
| 80 | 274 | return baos.toByteArray(); |
| 81 | |
} |
| 82 | |
|
| 83 | |
public void copyContent(TagField field) |
| 84 | |
{ |
| 85 | 0 | if (field instanceof Mp4TagTextNumberField) |
| 86 | |
{ |
| 87 | 0 | this.content = ((Mp4TagTextNumberField) field).getContent(); |
| 88 | 0 | this.numbers = ((Mp4TagTextNumberField) field).getNumbers(); |
| 89 | |
} |
| 90 | 0 | } |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
public Mp4FieldType getFieldType() |
| 96 | |
{ |
| 97 | 274 | return Mp4FieldType.IMPLICIT; |
| 98 | |
} |
| 99 | |
|
| 100 | |
protected void build(ByteBuffer data) throws UnsupportedEncodingException |
| 101 | |
{ |
| 102 | |
|
| 103 | 7 | Mp4BoxHeader header = new Mp4BoxHeader(data); |
| 104 | 7 | Mp4DataBox databox = new Mp4DataBox(header, data); |
| 105 | 7 | dataSize = header.getDataLength(); |
| 106 | 7 | content = databox.getContent(); |
| 107 | 7 | numbers = databox.getNumbers(); |
| 108 | 7 | } |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
public List<Short> getNumbers() |
| 114 | |
{ |
| 115 | 448 | return numbers; |
| 116 | |
} |
| 117 | |
} |