| 1 | |
package org.jaudiotagger.tag.mp4.field; |
| 2 | |
|
| 3 | |
import org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader; |
| 4 | |
import org.jaudiotagger.tag.FieldDataInvalidException; |
| 5 | |
import org.jaudiotagger.tag.mp4.Mp4FieldKey; |
| 6 | |
import org.jaudiotagger.tag.mp4.atom.Mp4DataBox; |
| 7 | |
|
| 8 | |
import java.io.UnsupportedEncodingException; |
| 9 | |
import java.nio.ByteBuffer; |
| 10 | |
import java.util.ArrayList; |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
public class Mp4DiscNoField extends Mp4TagTextNumberField |
| 23 | |
{ |
| 24 | |
private static final int NONE_VALUE_INDEX = 0; |
| 25 | |
private static final int DISC_NO_INDEX = 1; |
| 26 | |
private static final int DISC_TOTAL_INDEX = 2; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public Mp4DiscNoField(String discValue) throws FieldDataInvalidException |
| 35 | |
{ |
| 36 | 0 | super(Mp4FieldKey.DISCNUMBER.getFieldName(), discValue); |
| 37 | |
|
| 38 | 0 | numbers = new ArrayList<Short>(); |
| 39 | 0 | numbers.add(new Short("0")); |
| 40 | |
|
| 41 | 0 | String values[] = discValue.split("/"); |
| 42 | 0 | switch (values.length) |
| 43 | |
{ |
| 44 | |
case 1: |
| 45 | |
|
| 46 | |
try |
| 47 | |
{ |
| 48 | 0 | numbers.add(Short.parseShort(values[0])); |
| 49 | |
} |
| 50 | 0 | catch (NumberFormatException nfe) |
| 51 | |
{ |
| 52 | 0 | throw new FieldDataInvalidException("Value of:" + values[0] + " is invalid for field:" + id); |
| 53 | 0 | } |
| 54 | 0 | numbers.add(new Short("0")); |
| 55 | 0 | break; |
| 56 | |
|
| 57 | |
case 2: |
| 58 | |
try |
| 59 | |
{ |
| 60 | 0 | numbers.add(Short.parseShort(values[0])); |
| 61 | |
} |
| 62 | 0 | catch (NumberFormatException nfe) |
| 63 | |
{ |
| 64 | 0 | throw new FieldDataInvalidException("Value of:" + values[0] + " is invalid for field:" + id); |
| 65 | 0 | } |
| 66 | |
try |
| 67 | |
{ |
| 68 | 0 | numbers.add(Short.parseShort(values[1])); |
| 69 | |
} |
| 70 | 0 | catch (NumberFormatException nfe) |
| 71 | |
{ |
| 72 | 0 | throw new FieldDataInvalidException("Value of:" + values[1] + " is invalid for field:" + id); |
| 73 | 0 | } |
| 74 | |
break; |
| 75 | |
|
| 76 | |
default: |
| 77 | 0 | throw new FieldDataInvalidException("Value is invalid for field:" + id); |
| 78 | |
} |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
public Mp4DiscNoField(int discNo) |
| 88 | |
{ |
| 89 | 24 | super(Mp4FieldKey.DISCNUMBER.getFieldName(), String.valueOf(discNo)); |
| 90 | 24 | numbers = new ArrayList<Short>(); |
| 91 | 24 | numbers.add(new Short("0")); |
| 92 | 24 | numbers.add((short) discNo); |
| 93 | 24 | numbers.add(new Short("0")); |
| 94 | 24 | } |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public Mp4DiscNoField(int discNo, int total) |
| 103 | |
{ |
| 104 | 24 | super(Mp4FieldKey.DISCNUMBER.getFieldName(), String.valueOf(discNo)); |
| 105 | 24 | numbers = new ArrayList<Short>(); |
| 106 | 24 | numbers.add(new Short("0")); |
| 107 | 24 | numbers.add((short) discNo); |
| 108 | 24 | numbers.add((short) total); |
| 109 | 24 | } |
| 110 | |
|
| 111 | |
public Mp4DiscNoField(String id, ByteBuffer data) throws UnsupportedEncodingException |
| 112 | |
{ |
| 113 | 209 | super(id, data); |
| 114 | 209 | } |
| 115 | |
|
| 116 | |
protected void build(ByteBuffer data) throws UnsupportedEncodingException |
| 117 | |
{ |
| 118 | |
|
| 119 | 209 | Mp4BoxHeader header = new Mp4BoxHeader(data); |
| 120 | 209 | Mp4DataBox databox = new Mp4DataBox(header, data); |
| 121 | 209 | dataSize = header.getDataLength(); |
| 122 | 209 | numbers = databox.getNumbers(); |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | 209 | StringBuffer sb = new StringBuffer(); |
| 127 | 209 | sb.append(numbers.get(DISC_NO_INDEX)); |
| 128 | 209 | if (numbers.get(DISC_TOTAL_INDEX) > 0) |
| 129 | |
{ |
| 130 | 179 | sb.append("/").append(numbers.get(DISC_TOTAL_INDEX)); |
| 131 | |
} |
| 132 | 209 | content = sb.toString(); |
| 133 | 209 | } |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
public Short getDiscNo() |
| 139 | |
{ |
| 140 | 236 | return numbers.get(DISC_NO_INDEX); |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
public void setDiscNo(int discNo) |
| 149 | |
{ |
| 150 | 0 | numbers.set(DISC_NO_INDEX, (short) discNo); |
| 151 | 0 | } |
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
public Short getDiscTotal() |
| 157 | |
{ |
| 158 | 144 | return numbers.get(DISC_TOTAL_INDEX); |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
public void setDiscTotal(int discTotal) |
| 167 | |
{ |
| 168 | 0 | numbers.set(DISC_TOTAL_INDEX, (short) discTotal); |
| 169 | 0 | } |
| 170 | |
} |