Mp4TagByteFieldpublic class Mp4TagByteField extends Mp4TagTextField Represents a single byte as a number
Usually single byte fields are used as a boolean field, but not always so we dont do this conversion |
Fields Summary |
---|
public static String | TRUE_VALUE | private int | realDataLength | private byte[] | bytedata |
Constructors Summary |
---|
public Mp4TagByteField(org.jaudiotagger.tag.mp4.Mp4FieldKey id, String value)Create new field
Assume length of 1 which is correct for most but not all byte fields
this(id, value, 1);
| public Mp4TagByteField(org.jaudiotagger.tag.mp4.Mp4FieldKey id, String value, int realDataLength)Create new field with known length
super(id.getFieldName(), value);
this.realDataLength = realDataLength;
//Check that can actually be stored numercially, otherwise will have big problems
//when try and save the field
try
{
Long.parseLong(value);
}
catch (NumberFormatException nfe)
{
throw new FieldDataInvalidException("Value of:" + value + " is invalid for field:" + id);
}
| public Mp4TagByteField(String id, ByteBuffer raw)Construct from rawdata from audio file
super(id, raw);
|
Methods Summary |
---|
protected void | build(java.nio.ByteBuffer data)
//Data actually contains a 'Data' Box so process data using this
Mp4BoxHeader header = new Mp4BoxHeader(data);
Mp4DataBox databox = new Mp4DataBox(header, data);
dataSize = header.getDataLength();
//Needed for subsequent write
realDataLength = dataSize - Mp4DataBox.PRE_DATA_LENGTH;
bytedata = databox.getByteData();
content = databox.getContent();
| protected byte[] | getDataBytes()Return raw data bytes
TODO this code should be done better so generalised to any length
//Write original data
if (bytedata != null)
{
return bytedata;
}
//new field, lets hope the realDataLength is correct
switch (realDataLength)
{
case 2:
{
//Save as two bytes
Short shortValue = new Short(content);
byte rawData[] = Utils.getSizeBEInt16(shortValue);
return rawData;
}
case 1:
{
//Save as 1 bytes
Short shortValue = new Short(content);
byte rawData[] = new byte[1];
rawData[0] = shortValue.byteValue();
return rawData;
}
case 4:
{
//Assume could be int
Integer intValue = new Integer(content);
byte rawData[] = Utils.getSizeBEInt32(intValue);
return rawData;
}
default:
{
//TODO
throw new RuntimeException(id + ":" + realDataLength + ":" + "Dont know how to write byte fields of this length");
}
}
| public Mp4FieldType | getFieldType()
return Mp4FieldType.INTEGER;
|
|