GUIDpublic final class GUID extends Object This class is used for representation of GUIDs and as a reference list of all
Known GUIDs.
|
Fields Summary |
---|
public static final GUID | GUID_AUDIO_ERROR_CONCEALEMENT_ABSENTThis 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_INTERLEAVEDThis constant defines the GUID for stream chunks describing audio
streams, indicating the the audio stream has interleaved error
concealment.
| public static final GUID | GUID_AUDIOSTREAMThis constant stores the GUID indicating that stream type is audio. | public static final GUID | GUID_CONTENT_BRANDINGThis constant stores the GUID indicating a content branding object. | public static final GUID | GUID_CONTENT_ENCRYPTIONThis is for the Content Encryption Object
2211B3FB-BD23-11D2-B4B7-00A0C955FC6E, needs to be little-endian. | public static final GUID | GUID_CONTENTDESCRIPTIONThis constant represents the guidData for a chunk which contains Title,
author, copyright, description and rating. | public static final GUID | GUID_ENCODINGThis constant stores the GUID for Encoding-Info chunks. | public static final GUID | GUID_EXTENDED_CONTENT_DESCRIPTIONThis constant defines the GUID for a WMA "Extended Content Description"
chunk.
| public static final GUID | GUID_FILEGUID of ASF file header. | public static final GUID | GUID_HEADERThis constant defines the GUID of a asf header chunk. | public static final GUID | GUID_HEADER_EXTENSIONThis constant stores a GUID whose functionality is unknown. | public static final GUID | GUID_LANGUAGE_LISTThis constant stores the GUID indicating the asf language list object.
| public static final int | GUID_LENGTHThis constant stores the length of GUIDs used with ASF streams.
| public static final GUID | GUID_METADATAThis constant stores the GUID indicating the asf metadata object.
| public static final GUID | GUID_METADATA_LIBRARYThis constant stores the GUID indicating the asf metadata library object.
| private static final Pattern | GUID_PATTERNThe GUID String values format.
| public static final GUID | GUID_STREAMThis constant stores the GUID indicating a stream object. | public static final GUID | GUID_STREAM_BITRATE_PROPERTIESThis constant stores a GUID indicating a "stream bitrate properties"
chunk. | private static final Map | GUID_TO_CONFIGUREDThis 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_UNSPECIFIEDThis 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_VIDEOSTREAMThis constant stores the GUID indicating that stream type is video. | public static final GUID[] | KNOWN_GUIDSThis field stores all known GUIDs. | public static final GUID | SCRIPT_COMMAND_OBJECTThis constant stores the GUID for a "script command object".
| private String | descriptionStores an optionally description of the GUID. | private int[] | guidDataAn instance of this class stores the value of the wrapped GUID in this
field.
| private int | hashStores the hash code of the object.
"-1" if not determined yet. |
Constructors Summary |
---|
public GUID(byte[] value)Creates an instance and assigns given value .
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 .
setGUID(value);
| public GUID(int[] value, String desc)Creates an instance like {@link #GUID(int[])}and sets the optional
description.
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)})
this(parseGUID(guidString).getGUID());
if (desc == null) {
throw new IllegalArgumentException("Argument must not be null.");
}
this.description = desc;
|
Methods Summary |
---|
public static boolean | assertGUID(int[] value)This method checks if the given value is matching the GUID
specification of ASF streams.
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 boolean | equals(java.lang.Object obj)This method compares two objects. If the given Object is a {@link GUID},
the stored GUID values are compared.
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.
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.GUID | getConfigured(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.
// safe against null
return GUID_TO_CONFIGURED.get(orig);
| public java.lang.String | getDescription()
return this.description;
| public int[] | getGUID()This method returns the GUID of this object.
final int[] copy = new int[this.guidData.length];
System.arraycopy(this.guidData, 0, copy, 0, this.guidData.length);
return copy;
| public static java.lang.String | getGuidDescription(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.
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.
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 int | hashCode(){@inheritDoc}
if (this.hash == -1) {
int tmp = 0;
for (final int curr : getGUID()) {
tmp = tmp * 31 + curr;
}
this.hash = tmp;
}
return this.hash;
| public boolean | isValid()This method checks if the currently stored GUID ({@link #guidData}) is
correctly filled.
return assertGUID(getGUID());
| public static org.jaudiotagger.audio.asf.data.GUID | parseGUID(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
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.String | prettyPrint()This method gives a hex formatted representation of {@link #getGUID()}
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 void | setGUID(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[])}.
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.String | toString(){@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();
|
|