FileDocCategorySizeDatePackage
GUID.javaAPI DocJaudiotagger 2.0.419833Wed Mar 30 16:11:50 BST 2011org.jaudiotagger.audio.asf.data

GUID

public final class GUID extends Object
This class is used for representation of GUIDs and as a reference list of all Known GUIDs.
author
Christian Laireiter

Fields Summary
public static final GUID
GUID_AUDIO_ERROR_CONCEALEMENT_ABSENT
This constant defines the GUID for stream chunks describing audio streams, indicating the the audio stream has no error concealment.
public static final GUID
GUID_AUDIO_ERROR_CONCEALEMENT_INTERLEAVED
This constant defines the GUID for stream chunks describing audio streams, indicating the the audio stream has interleaved error concealment.
public static final GUID
GUID_AUDIOSTREAM
This constant stores the GUID indicating that stream type is audio.
public static final GUID
GUID_CONTENT_BRANDING
This constant stores the GUID indicating a content branding object.
public static final GUID
GUID_CONTENT_ENCRYPTION
This is for the Content Encryption Object 2211B3FB-BD23-11D2-B4B7-00A0C955FC6E, needs to be little-endian.
public static final GUID
GUID_CONTENTDESCRIPTION
This constant represents the guidData for a chunk which contains Title, author, copyright, description and rating.
public static final GUID
GUID_ENCODING
This constant stores the GUID for Encoding-Info chunks.
public static final GUID
GUID_EXTENDED_CONTENT_DESCRIPTION
This constant defines the GUID for a WMA "Extended Content Description" chunk.
public static final GUID
GUID_FILE
GUID of ASF file header.
public static final GUID
GUID_HEADER
This constant defines the GUID of a asf header chunk.
public static final GUID
GUID_HEADER_EXTENSION
This constant stores a GUID whose functionality is unknown.
public static final GUID
GUID_LANGUAGE_LIST
This constant stores the GUID indicating the asf language list object.
public static final int
GUID_LENGTH
This constant stores the length of GUIDs used with ASF streams.
public static final GUID
GUID_METADATA
This constant stores the GUID indicating the asf metadata object.
public static final GUID
GUID_METADATA_LIBRARY
This constant stores the GUID indicating the asf metadata library object.
private static final Pattern
GUID_PATTERN
The GUID String values format.
public static final GUID
GUID_STREAM
This constant stores the GUID indicating a stream object.
public static final GUID
GUID_STREAM_BITRATE_PROPERTIES
This constant stores a GUID indicating a "stream bitrate properties" chunk.
private static final Map
GUID_TO_CONFIGURED
This map is used, to get the description of a GUID instance, which has been created by reading.
The map comparison is done against the {@link GUID#guidData} field. But only the {@link #KNOWN_GUIDS} have a description set.
public static final GUID
GUID_UNSPECIFIED
This constant represents a GUID implementation which can be used for generic implementations, which have to provide a GUID, but do not really require a specific GUID to work.
public static final GUID
GUID_VIDEOSTREAM
This constant stores the GUID indicating that stream type is video.
public static final GUID[]
KNOWN_GUIDS
This field stores all known GUIDs.
public static final GUID
SCRIPT_COMMAND_OBJECT
This constant stores the GUID for a "script command object".
private String
description
Stores an optionally description of the GUID.
private int[]
guidData
An instance of this class stores the value of the wrapped GUID in this field.
private int
hash
Stores the hash code of the object.
"-1" if not determined yet.
Constructors Summary
public GUID(byte[] value)
Creates an instance and assigns given value.

param
value GUID, which should be assigned. (will be converted to int[])


                                        
        
        assert value != null;
        final int[] tmp = new int[value.length];
        for (int i = 0; i < value.length; i++) {
            tmp[i] = (0xFF & value[i]);
        }
        setGUID(tmp);
    
public GUID(int[] value)
Creates an instance and assigns given value.

param
value GUID, which should be assigned.

        setGUID(value);
    
public GUID(int[] value, String desc)
Creates an instance like {@link #GUID(int[])}and sets the optional description.

param
value GUID, which should be assigned.
param
desc Description for the GUID.

        this(value);
        if (desc == null) {
            throw new IllegalArgumentException("Argument must not be null.");
        }
        this.description = desc;
    
public GUID(String guidString, String desc)
Creates an instance like {@link #GUID(int[])} and sets the optional description. (the int[] is obtained by {@link GUID#parseGUID(String)})

param
guidString GUID, which should be assigned.
param
desc Description for the GUID.

        this(parseGUID(guidString).getGUID());
        if (desc == null) {
            throw new IllegalArgumentException("Argument must not be null.");
        }
        this.description = desc;
    
Methods Summary
public static booleanassertGUID(int[] value)
This method checks if the given value is matching the GUID specification of ASF streams.

param
value possible GUID.
return
true if value matches the specification of a GUID.


     
        KNOWN_GUIDS = new GUID[] { GUID_AUDIO_ERROR_CONCEALEMENT_ABSENT,
                GUID_CONTENTDESCRIPTION, GUID_AUDIOSTREAM, GUID_ENCODING,
                GUID_FILE, GUID_HEADER, GUID_STREAM,
                GUID_EXTENDED_CONTENT_DESCRIPTION, GUID_VIDEOSTREAM,
                GUID_HEADER_EXTENSION, GUID_STREAM_BITRATE_PROPERTIES,
                SCRIPT_COMMAND_OBJECT, GUID_CONTENT_ENCRYPTION,
                GUID_CONTENT_BRANDING, GUID_UNSPECIFIED, GUID_METADATA_LIBRARY,
                GUID_METADATA, GUID_LANGUAGE_LIST };
        GUID_TO_CONFIGURED = new HashMap<GUID, GUID>(KNOWN_GUIDS.length);
        for (final GUID curr : KNOWN_GUIDS) {
            assert !GUID_TO_CONFIGURED.containsKey(curr) : "Double definition: \""
                    + GUID_TO_CONFIGURED.get(curr).getDescription()
                    + "\" <-> \"" + curr.getDescription() + "\"";
            GUID_TO_CONFIGURED.put(curr, curr);
        }
    
        return value != null && value.length == GUID.GUID_LENGTH;
    
public booleanequals(java.lang.Object obj)
This method compares two objects. If the given Object is a {@link GUID}, the stored GUID values are compared.

see
java.lang.Object#equals(java.lang.Object)

        boolean result = false;
        if (obj instanceof GUID) {
            final GUID other = (GUID) obj;
            result = Arrays.equals(this.getGUID(), other.getGUID());
        }
        return result;
    
public byte[]getBytes()
This method returns the GUID as an array of bytes.

return
The GUID as a byte array.
see
#getGUID()

        final byte[] result = new byte[this.guidData.length];
        for (int i = 0; i < result.length; i++) {
            result[i] = (byte) (this.guidData[i] & 0xFF);
        }
        return result;
    
public static org.jaudiotagger.audio.asf.data.GUIDgetConfigured(org.jaudiotagger.audio.asf.data.GUID orig)
This method looks up a GUID instance from {@link #KNOWN_GUIDS} which matches the value of the given GUID.

param
orig GUID to look up.
return
a GUID instance from {@link #KNOWN_GUIDS} if available. null else.

        // safe against null
        return GUID_TO_CONFIGURED.get(orig);
    
public java.lang.StringgetDescription()

return
Returns the description.

        return this.description;
    
public int[]getGUID()
This method returns the GUID of this object.

return
stored GUID.

        final int[] copy = new int[this.guidData.length];
        System.arraycopy(this.guidData, 0, copy, 0, this.guidData.length);
        return copy;
    
public static java.lang.StringgetGuidDescription(org.jaudiotagger.audio.asf.data.GUID guid)
This method searches a GUID in {@link #KNOWN_GUIDS}which is equal to the given guidData and returns its description.
This method is useful if a GUID was read out of a file and no identification has been done yet.

param
guid GUID, which description is needed.
return
description of the GUID if found. Else null

        String result = null;
        if (guid == null) {
            throw new IllegalArgumentException("Argument must not be null.");
        }
        if (getConfigured(guid) != null) {
            result = getConfigured(guid).getDescription();
        }
        return result;
    
private java.lang.String[]getHex(byte[] bytes)
Convenience method to get 2digit hex values of each byte.

param
bytes bytes to convert.
return
each byte as 2 digit hex.

        final String[] result = new String[bytes.length];
        final StringBuilder tmp = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            tmp.delete(0, tmp.length());
            tmp.append(Integer.toHexString(0xFF & bytes[i]));
            if (tmp.length() == 1) {
                tmp.insert(0, "0");
            }
            result[i] = tmp.toString();
        }
        return result;
    
public inthashCode()
{@inheritDoc}

        if (this.hash == -1) {
            int tmp = 0;
            for (final int curr : getGUID()) {
                tmp = tmp * 31 + curr;
            }
            this.hash = tmp;
        }
        return this.hash;
    
public booleanisValid()
This method checks if the currently stored GUID ({@link #guidData}) is correctly filled.

return
true if it is.

        return assertGUID(getGUID());
    
public static org.jaudiotagger.audio.asf.data.GUIDparseGUID(java.lang.String guid)
This method parses a String as GUID.
The format is like the one in the ASF specification.
An Example: C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA

param
guid the string to parse.
return
the GUID.
throws
GUIDFormatException If the GUID has an invalid format.

        if (guid == null) {
            throw new GUIDFormatException("null");
        }
        if (!GUID_PATTERN.matcher(guid).matches()) {
            throw new GUIDFormatException("Invalid guidData format.");
        }
        final int[] bytes = new int[GUID_LENGTH];
        /*
         * Don't laugh, but did not really come up with a nicer solution today
         */
        final int[] arrayIndices = { 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12,
                13, 14, 15 };
        int arrayPointer = 0;
        for (int i = 0; i < guid.length(); i++) {
            if (guid.charAt(i) == '-") {
                continue;
            }
            bytes[arrayIndices[arrayPointer++]] = Integer.parseInt(guid
                    .substring(i, i + 2), 16);
            i++;
        }
        return new GUID(bytes);
    
public java.lang.StringprettyPrint()
This method gives a hex formatted representation of {@link #getGUID()}

return
hex formatted representation.

        final StringBuilder result = new StringBuilder();
        String descr = getDescription();
        if (Utils.isBlank(descr)) {
            descr = getGuidDescription(this);
        }
        if (!Utils.isBlank(descr)) {
            result.append("Description: ").append(descr).append(
                    Utils.LINE_SEPARATOR).append("   ");
        }
        result.append(this.toString());
        return result.toString();
    
private voidsetGUID(int[] value)
This method saves a copy of the given value as the represented value of this object.
The given value is checked with {@link #assertGUID(int[])}.

param
value GUID to assign.

        if (assertGUID(value)) {
            this.guidData = new int[GUID_LENGTH];
            System.arraycopy(value, 0, this.guidData, 0, GUID_LENGTH);
        } else {
            throw new IllegalArgumentException(
                    "The given guidData doesn't match the GUID specification.");
        }
    
public java.lang.StringtoString()
{@inheritDoc}

        // C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA
        // 0xea, 0xcb,0xf8, 0xc5, 0xaf, 0x5b, 0x77, 0x48, 0x84, 0x67, 0xaa,
        // 0x8c, 0x44,0xfa, 0x4c, 0xca
        final StringBuilder result = new StringBuilder();
        final String[] bytes = getHex(getBytes());
        result.append(bytes[3]);
        result.append(bytes[2]);
        result.append(bytes[1]);
        result.append(bytes[0]);
        result.append('-");
        result.append(bytes[5]);
        result.append(bytes[4]);
        result.append('-");
        result.append(bytes[7]);
        result.append(bytes[6]);
        result.append('-");
        result.append(bytes[8]);
        result.append(bytes[9]);
        result.append('-");
        result.append(bytes[10]);
        result.append(bytes[11]);
        result.append(bytes[12]);
        result.append(bytes[13]);
        result.append(bytes[14]);
        result.append(bytes[15]);
        return result.toString();