org.jaudiotagger.audio.asf.data
Class MetadataDescriptor

java.lang.Object
  extended by org.jaudiotagger.audio.asf.data.MetadataDescriptor
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<MetadataDescriptor>

public class MetadataDescriptor
extends java.lang.Object
implements java.lang.Comparable<MetadataDescriptor>, java.lang.Cloneable

This structure represents metadata objects in ASF MetadataContainer.
The values are checked against the capability introduced by the given ContainerType at construction.

Limitation: Even though some container types do not restrict the data size to Integer.MAX_VALUE, this implementation does it (due to java nature).
2 GiB of data should suffice, and even be to large for normal java heap.

Author:
Christian Laireiter

Field Summary
private  ContainerType containerType
          Stores the containerType of the descriptor.
private  byte[] content
          The binary representation of the value.
private  int descriptorType
          This field shows the type of the metadata descriptor.
static long DWORD_MAXVALUE
          Maximum value for WORD.
private  int languageIndex
          the index of the language in the language list this descriptor applies to.
private static java.util.logging.Logger LOGGER
          Logger instance.
static int MAX_LANG_INDEX
          The maximum language index allowed.
static int MAX_STREAM_NUMBER
          Maximum stream number.
private  java.lang.String name
          The name of the metadata descriptor.
static java.math.BigInteger QWORD_MAXVALUE
          Maximum value for a QWORD value (64 bit unsigned).
private  int streamNumber
          The number of the stream, this descriptor applies to.
static int TYPE_BINARY
          Constant for the metadata descriptor-type for binary data.
static int TYPE_BOOLEAN
          Constant for the metadata descriptor-type for booleans.
static int TYPE_DWORD
          Constant for the metadata descriptor-type for DWORD (32-bit unsigned).
static int TYPE_GUID
          Constant for the metadata descriptor-type for GUIDs (128-bit).
static int TYPE_QWORD
          Constant for the metadata descriptor-type for QWORD (64-bit unsinged).
static int TYPE_STRING
          Constant for the metadata descriptor-type for Strings.
static int TYPE_WORD
          Constant for the metadata descriptor-type for WORD (16-bit unsigned).
static int WORD_MAXVALUE
          Maximum value for WORD.
 
Constructor Summary
MetadataDescriptor(ContainerType type, java.lang.String propName, int propType)
          Creates an Instance.
MetadataDescriptor(ContainerType type, java.lang.String propName, int propType, int stream, int language)
          Creates an Instance.
MetadataDescriptor(java.lang.String propName)
          Creates an instance.
Capabilities are set to ContainerType.METADATA_LIBRARY_OBJECT.
MetadataDescriptor(java.lang.String propName, int propType)
          Creates an Instance.
Capabilities are set to ContainerType.METADATA_LIBRARY_OBJECT.
 
Method Summary
 java.math.BigInteger asNumber()
          Converts the descriptors value into a number if possible.
A boolean will be converted to "1" if true, otherwise "0".
String will be interpreted as number with radix "10".
Binary data will be interpreted as the default WORD,DWORD or QWORD binary representation, but only if the data does not exceed 8 bytes.
 java.lang.Object clone()
          (overridden)
 int compareTo(MetadataDescriptor other)
          
 MetadataDescriptor createCopy()
          This method creates a copy of the current object.
 boolean equals(java.lang.Object obj)
          (overridden)
 boolean getBoolean()
          Returns the value of the MetadataDescriptor as a Boolean.
 byte[] getBytes()
          Deprecated. writeInto(OutputStream,ContainerType) is used
 ContainerType getContainerType()
          Returns the container type this descriptor ist restricted to.
 int getCurrentAsfSize(ContainerType type)
          Returns the size (in bytes) this descriptor will take when written to an ASF file.
 GUID getGuid()
          Returns the GUID value, if content could represent one.
 int getLanguageIndex()
          Returns the index of the language that is referred (see LanguageList):
 java.lang.String getName()
          This method returns the name of the metadata descriptor.
 long getNumber()
          This method returns the value of the metadata descriptor as a long.
 byte[] getRawData()
          This method returns a copy of the content of the descriptor.
 int getRawDataSize()
          Returns the size (in bytes) the binary representation of the content uses.
 int getStreamNumber()
          Returns the stream number this descriptor applies to.
 java.lang.String getString()
          Returns the value of the MetadataDescriptor as a String.
 int getType()
          Returns the type of the metadata descriptor.
 int hashCode()
          
 boolean isEmpty()
          This method checks if the binary data is empty.
 void setBinaryValue(byte[] data)
          Sets the Value of the current metadata descriptor.
 void setBooleanValue(boolean value)
          Sets the Value of the current metadata descriptor.
 void setDWordValue(long value)
          Sets the Value of the current metadata descriptor.
 void setGUIDValue(GUID value)
          Sets the value of the metadata descriptor.
Using this method will change descriptorType to TYPE_GUID
 void setLanguageIndex(int language)
          Sets the index of the referred language (see LanguageList).
Consider: The requirements must be held.
 void setQWordValue(java.math.BigInteger value)
          Sets the Value of the current metadata descriptor.
 void setQWordValue(long value)
          Sets the Value of the current metadata descriptor.
 void setStreamNumber(int stream)
          Sets the stream number the descriptor applies to.
Consider: The requirements must be held.
 void setString(java.lang.String value)
          This method converts the given string value into the current data type.
 void setStringValue(java.lang.String value)
          Sets the Value of the current metadata descriptor.
 void setWordValue(int value)
          Sets the Value of the current metadata descriptor.
 java.lang.String toString()
          (overridden)
 int writeInto(java.io.OutputStream out, ContainerType contType)
          Writes this descriptor into the specified output stream.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DWORD_MAXVALUE

public static final long DWORD_MAXVALUE
Maximum value for WORD.


LOGGER

private static final java.util.logging.Logger LOGGER
Logger instance.


MAX_LANG_INDEX

public static final int MAX_LANG_INDEX
The maximum language index allowed. (exclusive)

See Also:
Constant Field Values

MAX_STREAM_NUMBER

public static final int MAX_STREAM_NUMBER
Maximum stream number. (inclusive)

See Also:
Constant Field Values

QWORD_MAXVALUE

public static final java.math.BigInteger QWORD_MAXVALUE
Maximum value for a QWORD value (64 bit unsigned).


TYPE_BINARY

public static final int TYPE_BINARY
Constant for the metadata descriptor-type for binary data.

See Also:
Constant Field Values

TYPE_BOOLEAN

public static final int TYPE_BOOLEAN
Constant for the metadata descriptor-type for booleans.

See Also:
Constant Field Values

TYPE_DWORD

public static final int TYPE_DWORD
Constant for the metadata descriptor-type for DWORD (32-bit unsigned).

See Also:
Constant Field Values

TYPE_GUID

public static final int TYPE_GUID
Constant for the metadata descriptor-type for GUIDs (128-bit).

See Also:
Constant Field Values

TYPE_QWORD

public static final int TYPE_QWORD
Constant for the metadata descriptor-type for QWORD (64-bit unsinged).

See Also:
Constant Field Values

TYPE_STRING

public static final int TYPE_STRING
Constant for the metadata descriptor-type for Strings.

See Also:
Constant Field Values

TYPE_WORD

public static final int TYPE_WORD
Constant for the metadata descriptor-type for WORD (16-bit unsigned).

See Also:
Constant Field Values

WORD_MAXVALUE

public static final int WORD_MAXVALUE
Maximum value for WORD.

See Also:
Constant Field Values

containerType

private final ContainerType containerType
Stores the containerType of the descriptor.


content

private byte[] content
The binary representation of the value.


descriptorType

private int descriptorType
This field shows the type of the metadata descriptor.

See Also:
TYPE_BINARY, TYPE_BOOLEAN, TYPE_DWORD, TYPE_GUID, TYPE_QWORD, TYPE_STRING, TYPE_WORD

languageIndex

private int languageIndex
the index of the language in the language list this descriptor applies to.


name

private final java.lang.String name
The name of the metadata descriptor.


streamNumber

private int streamNumber
The number of the stream, this descriptor applies to.

Constructor Detail

MetadataDescriptor

public MetadataDescriptor(ContainerType type,
                          java.lang.String propName,
                          int propType)
Creates an Instance.

Parameters:
type - the container type, this descriptor is resctricted to.
propName - Name of the MetadataDescriptor.
propType - Type of the metadata descriptor. See descriptorType

MetadataDescriptor

public MetadataDescriptor(ContainerType type,
                          java.lang.String propName,
                          int propType,
                          int stream,
                          int language)
Creates an Instance.

Parameters:
type - The container type the values (the whole descriptor) is restricted to.
propName - Name of the MetadataDescriptor.
propType - Type of the metadata descriptor. See descriptorType
stream - the number of the stream the descriptor refers to.
language - the index of the language entry in a LanguageList this descriptor refers to.
Consider: No checks performed if language entry exists.

MetadataDescriptor

public MetadataDescriptor(java.lang.String propName)
Creates an instance.
Capabilities are set to ContainerType.METADATA_LIBRARY_OBJECT.

Parameters:
propName - name of the metadata descriptor.

MetadataDescriptor

public MetadataDescriptor(java.lang.String propName,
                          int propType)
Creates an Instance.
Capabilities are set to ContainerType.METADATA_LIBRARY_OBJECT.

Parameters:
propName - Name of the MetadataDescriptor.
propType - Type of the metadata descriptor. See descriptorType
Method Detail

asNumber

public java.math.BigInteger asNumber()
Converts the descriptors value into a number if possible.
A boolean will be converted to "1" if true, otherwise "0".
String will be interpreted as number with radix "10".
Binary data will be interpreted as the default WORD,DWORD or QWORD binary representation, but only if the data does not exceed 8 bytes. This precaution is done to prevent creating a number of a multi kilobyte image.
A GUID cannot be converted in any case.

Returns:
number representation.
Throws:
java.lang.NumberFormatException - If no conversion is supported.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
(overridden)

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException
See Also:
Object.clone()

compareTo

public int compareTo(MetadataDescriptor other)

Specified by:
compareTo in interface java.lang.Comparable<MetadataDescriptor>

createCopy

public MetadataDescriptor createCopy()
This method creates a copy of the current object.
All data will be copied, too.

Returns:
A new metadata descriptor containing the same values as the current one.

equals

public boolean equals(java.lang.Object obj)
(overridden)

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

getBoolean

public boolean getBoolean()
Returns the value of the MetadataDescriptor as a Boolean.
If no Conversion is Possible false is returned.
true if first byte of contentis not zero.

Returns:
boolean representation of the current value.

getBytes

@Deprecated
public byte[] getBytes()
Deprecated. writeInto(OutputStream,ContainerType) is used

This method will return a byte array, which can directly be written into an "Extended Content Description"-chunk.

Returns:
byte[] with the data, that occurs in ASF files.

getContainerType

public ContainerType getContainerType()
Returns the container type this descriptor ist restricted to.

Returns:
the container type

getCurrentAsfSize

public int getCurrentAsfSize(ContainerType type)
Returns the size (in bytes) this descriptor will take when written to an ASF file.

Parameters:
type - the container type for which the size is calculated.
Returns:
size of the descriptor in an ASF file.

getGuid

public GUID getGuid()
Returns the GUID value, if content could represent one.

Returns:
GUID value

getLanguageIndex

public int getLanguageIndex()
Returns the index of the language that is referred (see LanguageList):

Returns:
the language index

getName

public java.lang.String getName()
This method returns the name of the metadata descriptor.

Returns:
Name.

getNumber

public long getNumber()
This method returns the value of the metadata descriptor as a long.
Converts the needed amount of byte out of contentto a number.
Only possible if getType()equals on of the following:
  • Returns:
    integer value.
    See Also:
  • ,
  • ,
  • ,

  • getRawData

    public byte[] getRawData()
    This method returns a copy of the content of the descriptor.

    Returns:
    The content in binary representation, as it would be written to asf file.

    getRawDataSize

    public int getRawDataSize()
    Returns the size (in bytes) the binary representation of the content uses. (length of getRawData())

    Returns:
    size of binary representation of the content.

    getStreamNumber

    public int getStreamNumber()
    Returns the stream number this descriptor applies to.

    Returns:
    the stream number.

    getString

    public java.lang.String getString()
    Returns the value of the MetadataDescriptor as a String.

    Returns:
    String - Representation Value

    getType

    public int getType()
    Returns the type of the metadata descriptor.

    Returns:
    the value of descriptorType
    See Also:
    TYPE_BINARY, TYPE_BOOLEAN, TYPE_DWORD, TYPE_GUID, TYPE_QWORD, TYPE_STRING, TYPE_WORD

    hashCode

    public int hashCode()

    Overrides:
    hashCode in class java.lang.Object

    isEmpty

    public boolean isEmpty()
    This method checks if the binary data is empty.
    Disregarding the type of the descriptor its content is stored as a byte array.

    Returns:
    true if no value is set.

    setBinaryValue

    public void setBinaryValue(byte[] data)
                        throws java.lang.IllegalArgumentException
    Sets the Value of the current metadata descriptor.
    Using this method will change descriptorTypeto TYPE_BINARY.

    Parameters:
    data - Value to set.
    Throws:
    java.lang.IllegalArgumentException - if data is invalid for container.

    setBooleanValue

    public void setBooleanValue(boolean value)
    Sets the Value of the current metadata descriptor.
    Using this method will change descriptorTypeto TYPE_BOOLEAN.

    Parameters:
    value - Value to set.

    setDWordValue

    public void setDWordValue(long value)
    Sets the Value of the current metadata descriptor.
    Using this method will change descriptorTypeto TYPE_DWORD.

    Parameters:
    value - Value to set.

    setGUIDValue

    public void setGUIDValue(GUID value)
    Sets the value of the metadata descriptor.
    Using this method will change descriptorType to TYPE_GUID

    Parameters:
    value - value to set.

    setLanguageIndex

    public void setLanguageIndex(int language)
    Sets the index of the referred language (see LanguageList).
    Consider: The requirements must be held.

    Parameters:
    language - the language index to set

    setQWordValue

    public void setQWordValue(java.math.BigInteger value)
                       throws java.lang.IllegalArgumentException
    Sets the Value of the current metadata descriptor.
    Using this method will change descriptorTypeto TYPE_QWORD

    Parameters:
    value - Value to set.
    Throws:
    java.lang.NumberFormatException - on null values.
    java.lang.IllegalArgumentException - on illegal values or values exceeding range.

    setQWordValue

    public void setQWordValue(long value)
    Sets the Value of the current metadata descriptor.
    Using this method will change descriptorTypeto TYPE_QWORD

    Parameters:
    value - Value to set.

    setStreamNumber

    public void setStreamNumber(int stream)
    Sets the stream number the descriptor applies to.
    Consider: The requirements must be held.

    Parameters:
    stream - the stream number to set

    setString

    public void setString(java.lang.String value)
                   throws java.lang.IllegalArgumentException
    This method converts the given string value into the current data type.

    Parameters:
    value - value to set.
    Throws:
    java.lang.IllegalArgumentException - If conversion was impossible.

    setStringValue

    public void setStringValue(java.lang.String value)
                        throws java.lang.IllegalArgumentException
    Sets the Value of the current metadata descriptor.
    Using this method will change descriptorTypeto TYPE_STRING.

    Parameters:
    value - Value to set.
    Throws:
    java.lang.IllegalArgumentException - If byte representation would take more than 65535 Bytes.

    setWordValue

    public void setWordValue(int value)
                      throws java.lang.IllegalArgumentException
    Sets the Value of the current metadata descriptor.
    Using this method will change descriptorTypeto TYPE_WORD

    Parameters:
    value - Value to set.
    Throws:
    java.lang.IllegalArgumentException - on negative values. ASF just supports unsigned values.

    toString

    public java.lang.String toString()
    (overridden)

    Overrides:
    toString in class java.lang.Object
    See Also:
    Object.toString()

    writeInto

    public int writeInto(java.io.OutputStream out,
                         ContainerType contType)
                  throws java.io.IOException
    Writes this descriptor into the specified output stream.

    Parameters:
    out - stream to write into.
    contType - the container type this descriptor is written to.
    Returns:
    amount of bytes written.
    Throws:
    java.io.IOException - on I/O Errors