FileDocCategorySizeDatePackage
ID3Tags.javaAPI DocJaudiotagger 2.0.414826Wed Mar 30 16:12:06 BST 2011org.jaudiotagger.tag.id3

ID3Tags

public class ID3Tags extends Object
This contains static methods that can be performed on tags and to convert between tags.
author
: Paul Taylor
author
: Eric Farng
version
$Id: ID3Tags.java 919 2010-10-04 13:46:39Z paultaylor $

Fields Summary
public static Logger
logger
Constructors Summary
private ID3Tags()



     
    
    
Methods Summary
public static java.lang.StringconvertFrameID22To23(java.lang.String identifier)
Convert from ID3v22 FrameIdentifier to ID3v23

param
identifier
return

        if (identifier.length() < 3)
        {
            return null;
        }
        return ID3Frames.convertv22Tov23.get((String)identifier.subSequence(0, 3));
    
public static java.lang.StringconvertFrameID22To24(java.lang.String identifier)
Convert from ID3v22 FrameIdentifier to ID3v24

param
identifier
return

        //Idv22 identifiers are only of length 3 times
        if (identifier.length() < 3)
        {
            return null;
        }
        //Has idv22 been mapped to v23
        String id = ID3Frames.convertv22Tov23.get(identifier.substring(0, 3));
        if (id != null)
        {
            //has v2.3 been mapped to v2.4
            String v23id = ID3Frames.convertv23Tov24.get(id);
            if (v23id == null)
            {
                //if not it may be because v2.3 and and v2.4 are same so wont be
                //in mapping
                if (ID3v24Frames.getInstanceOf().getIdToValueMap().get(id) != null)
                {
                    return id;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return v23id;
            }
        }
        else
        {
            return null;
        }
    
public static java.lang.StringconvertFrameID23To22(java.lang.String identifier)
Convert from ID3v23 FrameIdentifier to ID3v22

param
identifier
return

        if (identifier.length() < 4)
        {
            return null;
        }

        //If it is a v23 identifier
        if (ID3v23Frames.getInstanceOf().getIdToValueMap().containsKey(identifier))
        {
            //If only name has changed  v22 and modified in v23 return result of.
            return ID3Frames.convertv23Tov22.get(identifier.substring(0, 4));
        }
        return null;
    
public static java.lang.StringconvertFrameID23To24(java.lang.String identifier)
Convert from ID3v23 FrameIdentifier to ID3v24

param
identifier
return

        if (identifier.length() < 4)
        {
            return null;
        }

        //If it is a ID3v23 identifier
        if (ID3v23Frames.getInstanceOf().getIdToValueMap().containsKey(identifier))
        {
            //If no change between ID3v23 and ID3v24 should be in ID3v24 list.
            if (ID3v24Frames.getInstanceOf().getIdToValueMap().containsKey(identifier))
            {
                return identifier;
            }
            //If only name has changed  ID3v23 and modified in ID3v24 return result of.
            else
            {
                return ID3Frames.convertv23Tov24.get(identifier.substring(0, 4));
            }
        }
        return null;
    
public static java.lang.StringconvertFrameID24To23(java.lang.String identifier)
Convert from ID3v24 FrameIdentifier to ID3v23

param
identifier
return

        String id;
        if (identifier.length() < 4)
        {
            return null;
        }
        id = ID3Frames.convertv24Tov23.get(identifier);
        if (id == null)
        {
            if (ID3v23Frames.getInstanceOf().getIdToValueMap().containsKey(identifier))
            {
                id = identifier;
            }
        }
        return id;
    
public static java.lang.ObjectcopyObject(java.lang.Object copyObject)
Unable to instantiate abstract classes, so can't call the copy constructor. So find out the instantiated class name and call the copy constructor through reflection (e.g for a a FrameBody would have to have a constructor that takes another frameBody as the same type as a parameter)

param
copyObject
return
throws
IllegalArgumentException if no suitable constructor exists

        Constructor<?> constructor;
        Class<?>[] constructorParameterArray;
        Object[] parameterArray;
        if (copyObject == null)
        {
            return null;
        }
        try
        {
            constructorParameterArray = new Class[1];
            constructorParameterArray[0] = copyObject.getClass();
            constructor = copyObject.getClass().getConstructor(constructorParameterArray);
            parameterArray = new Object[1];
            parameterArray[0] = copyObject;
            return constructor.newInstance(parameterArray);
        }
        catch (NoSuchMethodException ex)
        {
            throw new IllegalArgumentException("NoSuchMethodException: Error finding constructor to create copy:"+copyObject.getClass().getName());
        }
        catch (IllegalAccessException ex)
        {
            throw new IllegalArgumentException("IllegalAccessException: No access to run constructor to create copy"+copyObject.getClass().getName());
        }
        catch (InstantiationException ex)
        {
            throw new IllegalArgumentException("InstantiationException: Unable to instantiate constructor to copy"+copyObject.getClass().getName());
        }
        catch (java.lang.reflect.InvocationTargetException ex)
        {
            if (ex.getCause() instanceof Error)
            {
                throw (Error) ex.getCause();
            }
            else if (ex.getCause() instanceof RuntimeException)
            {
                throw (RuntimeException) ex.getCause();
            }
            else
            {
                throw new IllegalArgumentException("InvocationTargetException: Unable to invoke constructor to create copy");
            }
        }
    
public static longfindNumber(java.lang.String str)
Find the first whole number that can be parsed from the string

param
str string to search
return
first whole number that can be parsed from the string
throws
TagException

        return findNumber(str, 0);
    
public static longfindNumber(java.lang.String str, int offset)
Find the first whole number that can be parsed from the string

param
str string to search
param
offset start seaching from this index
return
first whole number that can be parsed from the string
throws
TagException
throws
NullPointerException
throws
IndexOutOfBoundsException

        if (str == null)
        {
            throw new NullPointerException("String is null");
        }
        if ((offset < 0) || (offset >= str.length()))
        {
            throw new IndexOutOfBoundsException("Offset to image string is out of bounds: offset = " + offset + ", string.length()" + str.length());
        }
        int i;
        int j;
        long num;
        i = offset;
        while (i < str.length())
        {
            if (((str.charAt(i) >= '0") && (str.charAt(i) <= '9")) || (str.charAt(i) == '-"))
            {
                break;
            }
            i++;
        }
        j = i + 1;
        while (j < str.length())
        {
            if (((str.charAt(j) < '0") || (str.charAt(j) > '9")))
            {
                break;
            }
            j++;
        }
        if ((j <= str.length()) && (j > i))
        {
            num = Long.parseLong(str.substring(i, j));
        }
        else
        {
            throw new TagException("Unable to find integer in string: " + str);
        }
        return num;
    
public static java.lang.StringforceFrameID22To23(java.lang.String identifier)
Force from ID3v22 FrameIdentifier to ID3v23, this is where the frame and structure has changed from v2 to v3 but we can still do some kind of conversion.

param
identifier
return

        return ID3Frames.forcev22Tov23.get(identifier);
    
public static java.lang.StringforceFrameID23To22(java.lang.String identifier)
Force from ID3v22 FrameIdentifier to ID3v23, this is where the frame and structure has changed from v2 to v3 but we can still do some kind of conversion.

param
identifier
return

        return ID3Frames.forcev23Tov22.get(identifier);
    
public static java.lang.StringforceFrameID23To24(java.lang.String identifier)
Force from ID3v2.30 FrameIdentifier to ID3v2.40, this is where the frame and structure has changed from v3 to v4 but we can still do some kind of conversion.

param
identifier
return

        return ID3Frames.forcev23Tov24.get(identifier);
    
public static java.lang.StringforceFrameID24To23(java.lang.String identifier)
Force from ID3v2.40 FrameIdentifier to ID3v2.30, this is where the frame and structure has changed between v4 to v3 but we can still do some kind of conversion.

param
identifier
return

        return ID3Frames.forcev24Tov23.get(identifier);
    
public static longgetWholeNumber(java.lang.Object value)
Given an datatype, try to return it as a long. This tries to parse a string, and takes Long, Short, Byte, Integer objects and gets their value. An exception is not explicitly thrown here because it would causes too many other methods to also throw it.

param
value datatype to find long from.
return
long value
throws
IllegalArgumentException

        long number;
        if (value instanceof String)
        {
            number = Long.parseLong((String) value);
        }
        else if (value instanceof Byte)
        {
            number = (Byte) value;
        }
        else if (value instanceof Short)
        {
            number = (Short) value;
        }
        else if (value instanceof Integer)
        {
            number = (Integer) value;
        }
        else if (value instanceof Long)
        {
            number = (Long) value;
        }
        else
        {
            throw new IllegalArgumentException("Unsupported value class: " + value.getClass().getName());
        }
        return number;
    
public static booleanisID3v22FrameIdentifier(java.lang.String identifier)
Returns true if the identifier is a valid ID3v2.2 frame identifier

param
identifier string to test
return
true if the identifier is a valid ID3v2.2 frame identifier

        //If less than 3 cant be an identifier
        if (identifier.length() < 3)
        {
            return false;
        }
        //If 3 is it a known identifier
        else return identifier.length() == 3 && ID3v22Frames.getInstanceOf().getIdToValueMap().containsKey(identifier);
    
public static booleanisID3v23FrameIdentifier(java.lang.String identifier)
Returns true if the identifier is a valid ID3v2.3 frame identifier

param
identifier string to test
return
true if the identifier is a valid ID3v2.3 frame identifier

        return identifier.length() >= 4 && ID3v23Frames.getInstanceOf().getIdToValueMap().containsKey(identifier.substring(0, 4));
    
public static booleanisID3v24FrameIdentifier(java.lang.String identifier)
Returns true if the identifier is a valid ID3v2.4 frame identifier

param
identifier string to test
return
true if the identifier is a valid ID3v2.4 frame identifier

        return identifier.length() >= 4 && ID3v24Frames.getInstanceOf().getIdToValueMap().containsKey(identifier.substring(0, 4));
    
public static java.lang.StringstripChar(java.lang.String str, char ch)
Remove all occurances of the given character from the string argument.

param
str String to search
param
ch character to remove
return
new String without the given charcter

        if (str != null)
        {
            char[] buffer = new char[str.length()];
            int next = 0;
            for (int i = 0; i < str.length(); i++)
            {
                if (str.charAt(i) != ch)
                {
                    buffer[next++] = str.charAt(i);
                }
            }
            return new String(buffer, 0, next);
        }
        else
        {
            return null;
        }
    
public static java.lang.Stringtruncate(java.lang.String str, int len)
truncate a string if it longer than the argument

param
str String to truncate
param
len maximum desired length of new string
return

        if (str == null)
        {
            return null;
        }
        if (len < 0)
        {
            return null;
        }
        if (str.length() > len)
        {
            return str.substring(0, len);
        }
        else
        {
            return str;
        }