Methods Summary |
---|
public boolean | equals(java.lang.Object obj)
if(obj==this)
{
return true;
}
if (!(obj instanceof PartOfSet))
{
return false;
}
PartOfSet that = (PartOfSet) obj;
return EqualsUtil.areEqual(value, that.value);
|
protected java.lang.String | getTextEncodingCharSet()Get the text encoding being used.
The text encoding is defined by the frame body that the text field belongs to.
byte textEncoding = this.getBody().getTextEncoding();
String charSetName = TextEncoding.getInstanceOf().getValueForId(textEncoding);
logger.finest("text encoding:" + textEncoding + " charset:" + charSetName);
return charSetName;
|
public org.jaudiotagger.tag.datatype.PartOfSet$PartOfSetValue | getValue()
return (PartOfSetValue)value;
|
public void | readByteArray(byte[] arr, int offset)Read a 'n' bytes from buffer into a String where n is the framesize - offset
so thefore cannot use this if there are other objects after it because it has no
delimiter.
Must take into account the text encoding defined in the Encoding Object
ID3 Text Frames often allow multiple strings seperated by the null char
appropriate for the encoding.
logger.finest("Reading from array from offset:" + offset);
//Get the Specified Decoder
String charSetName = getTextEncodingCharSet();
CharsetDecoder decoder = Charset.forName(charSetName).newDecoder();
//Decode sliced inBuffer
ByteBuffer inBuffer = ByteBuffer.wrap(arr, offset, arr.length - offset).slice();
CharBuffer outBuffer = CharBuffer.allocate(arr.length - offset);
decoder.reset();
CoderResult coderResult = decoder.decode(inBuffer, outBuffer, true);
if (coderResult.isError())
{
logger.warning("Decoding error:" + coderResult.toString());
}
decoder.flush(outBuffer);
outBuffer.flip();
//Store value
String stringValue = outBuffer.toString();
value = new PartOfSetValue(stringValue);
//SetSize, important this is correct for finding the next datatype
setSize(arr.length - offset);
logger.config("Read SizeTerminatedString:" + value + " size:" + size);
|
public java.lang.String | toString()
return value.toString();
|
public byte[] | writeByteArray()Write String into byte array
It will remove a trailing null terminator if exists if the option
RemoveTrailingTerminatorOnWrite has been set.
String value = getValue().toString();
byte[] data;
//Try and write to buffer using the CharSet defined by getTextEncodingCharSet()
try
{
if (TagOptionSingleton.getInstance().isRemoveTrailingTerminatorOnWrite())
{
if (value.length() > 0)
{
if (value.charAt(value.length() - 1) == '\0")
{
value = value.substring(0, value.length() - 1);
}
}
}
String charSetName = getTextEncodingCharSet();
if (charSetName.equals(TextEncoding.CHARSET_UTF_16))
{
charSetName = TextEncoding.CHARSET_UTF_16_LE_ENCODING_FORMAT;
CharsetEncoder encoder = Charset.forName(charSetName).newEncoder();
//Note remember LE BOM is ff fe but this is handled by encoder Unicode char is fe ff
ByteBuffer bb = encoder.encode(CharBuffer.wrap('\ufeff" + value));
data = new byte[bb.limit()];
bb.get(data, 0, bb.limit());
}
else
{
CharsetEncoder encoder = Charset.forName(charSetName).newEncoder();
ByteBuffer bb = encoder.encode(CharBuffer.wrap( value));
data = new byte[bb.limit()];
bb.get(data, 0, bb.limit());
}
}
//Should never happen so if does throw a RuntimeException
catch (CharacterCodingException ce)
{
logger.severe(ce.getMessage());
throw new RuntimeException(ce);
}
setSize(data.length);
return data;
|