org.jaudiotagger.tag.datatype
Class TextEncodedStringSizeTerminated

java.lang.Object
  extended by org.jaudiotagger.tag.datatype.AbstractDataType
      extended by org.jaudiotagger.tag.datatype.AbstractString
          extended by org.jaudiotagger.tag.datatype.TextEncodedStringSizeTerminated
Direct Known Subclasses:
StringSizeTerminated

public class TextEncodedStringSizeTerminated
extends AbstractString

Represents a String which is not delimited by null character.

This type of String will usually only be used when it is the last field within a frame, when reading the remainder of the byte array will be read, when writing the frame will be accommodate the required size for the String. The String will be encoded based upon the text encoding of the frame that it belongs to.

All TextInformation frames support multiple strings, stored as a null separated list, where null is represented by the termination code for the character encoding. This functionality is only officially support in ID3v24. Most applications will ignore any but the first value, but some such as Foobar 2000 will decode them properly iTunes write null terminators characters after the String even though it only writes a single value.


Field Summary
 
Fields inherited from class org.jaudiotagger.tag.datatype.AbstractDataType
frameBody, identifier, logger, size, TYPE_ELEMENT, value
 
Constructor Summary
TextEncodedStringSizeTerminated(java.lang.String identifier, AbstractTagFrameBody frameBody)
          Creates a new empty TextEncodedStringSizeTerminated datatype.
TextEncodedStringSizeTerminated(TextEncodedStringSizeTerminated object)
          Copy constructor
 
Method Summary
 void addValue(java.lang.String value)
          Add an additional String to the current String value
private  void checkTrailingNull(java.util.List<java.lang.String> values, java.lang.String stringValue)
          Because nulls are stripped we need to check if not removing trailing nulls whether the original value ended with a null and if so add it back in.
 boolean equals(java.lang.Object obj)
           
 int getNumberOfValues()
          How many values are held, each value is separated by a null terminator
protected  java.lang.String getTextEncodingCharSet()
          Get the text encoding being used.
 java.lang.String getValueAtIndex(int index)
          Get the nth value
 java.util.List<java.lang.String> getValues()
           
 java.lang.String getValueWithoutTrailingNull()
          Get value(s) whilst removing any trailing nulls
 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.
static java.util.List<java.lang.String> splitByNullSeperator(java.lang.String value)
          Split the values separated by null character
private  void stripTrailingNull()
          Removing trailing null from end of String, this should be there but some applications continue to write this unnecessary null char.
 byte[] writeByteArray()
          Write String into byte array

It will remove a trailing null terminator if exists if the option RemoveTrailingTerminatorOnWrite has been set.

private  java.nio.ByteBuffer writeString(java.nio.charset.CharsetEncoder encoder, java.lang.String next, int i, int noOfValues)
          Write String using specified encoding When this is called multiple times, all but the last value has a trailing null
private  java.nio.ByteBuffer writeStringUTF16LEBOM(java.lang.String next, int i, int noOfValues)
          Write String in UTF-LEBOM format When this is called multiple times, all but the last value has a trailing null Remember we are using this charset because the charset that writes BOM does it the wrong way for us so we use this none and then manually add the BOM ourselves.
 
Methods inherited from class org.jaudiotagger.tag.datatype.AbstractString
canBeEncoded, getSize, setSize, toString
 
Methods inherited from class org.jaudiotagger.tag.datatype.AbstractDataType
createStructure, getBody, getIdentifier, getValue, readByteArray, setBody, setValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextEncodedStringSizeTerminated

public TextEncodedStringSizeTerminated(java.lang.String identifier,
                                       AbstractTagFrameBody frameBody)
Creates a new empty TextEncodedStringSizeTerminated datatype.

Parameters:
identifier - identifies the frame type
frameBody -

TextEncodedStringSizeTerminated

public TextEncodedStringSizeTerminated(TextEncodedStringSizeTerminated object)
Copy constructor

Parameters:
object -
Method Detail

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class AbstractDataType
Returns:
whether this and obj are deemed equivalent

readByteArray

public void readByteArray(byte[] arr,
                          int offset)
                   throws InvalidDataTypeException
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.

Specified by:
readByteArray in class AbstractDataType
Parameters:
arr - this is the buffer for the frame
offset - this is where to start reading in the buffer for this field
Throws:
java.lang.NullPointerException
java.lang.IndexOutOfBoundsException
InvalidDataTypeException

writeString

private java.nio.ByteBuffer writeString(java.nio.charset.CharsetEncoder encoder,
                                        java.lang.String next,
                                        int i,
                                        int noOfValues)
                                 throws java.nio.charset.CharacterCodingException
Write String using specified encoding When this is called multiple times, all but the last value has a trailing null

Parameters:
encoder -
next -
i -
noOfValues -
Returns:
Throws:
java.nio.charset.CharacterCodingException

writeStringUTF16LEBOM

private java.nio.ByteBuffer writeStringUTF16LEBOM(java.lang.String next,
                                                  int i,
                                                  int noOfValues)
                                           throws java.nio.charset.CharacterCodingException
Write String in UTF-LEBOM format When this is called multiple times, all but the last value has a trailing null Remember we are using this charset because the charset that writes BOM does it the wrong way for us so we use this none and then manually add the BOM ourselves.

Parameters:
next -
i -
noOfValues -
Returns:
Throws:
java.nio.charset.CharacterCodingException

stripTrailingNull

private void stripTrailingNull()
Removing trailing null from end of String, this should be there but some applications continue to write this unnecessary null char.


checkTrailingNull

private void checkTrailingNull(java.util.List<java.lang.String> values,
                               java.lang.String stringValue)
Because nulls are stripped we need to check if not removing trailing nulls whether the original value ended with a null and if so add it back in.

Parameters:
values -
stringValue -

writeByteArray

public byte[] writeByteArray()
Write String into byte array

It will remove a trailing null terminator if exists if the option RemoveTrailingTerminatorOnWrite has been set.

Specified by:
writeByteArray in class AbstractDataType
Returns:
the data as a byte array in format to write to file

getTextEncodingCharSet

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.

Returns:
the text encoding charset

splitByNullSeperator

public static java.util.List<java.lang.String> splitByNullSeperator(java.lang.String value)
Split the values separated by null character

Parameters:
value - the raw value
Returns:
list of values, guaranteed to be at least one value

addValue

public void addValue(java.lang.String value)
Add an additional String to the current String value

Parameters:
value -

getNumberOfValues

public int getNumberOfValues()
How many values are held, each value is separated by a null terminator

Returns:
number of values held, usually this will be one.

getValueAtIndex

public java.lang.String getValueAtIndex(int index)
Get the nth value

Parameters:
index -
Returns:
the nth value
Throws:
java.lang.IndexOutOfBoundsException - if value does not exist

getValues

public java.util.List<java.lang.String> getValues()
Returns:
list of all values

getValueWithoutTrailingNull

public java.lang.String getValueWithoutTrailingNull()
Get value(s) whilst removing any trailing nulls

Returns:


Copyright © 2005-2010 java.net. All Rights Reserved.