org.farng.mp3
Class TagUtility

java.lang.Object
  extended byorg.farng.mp3.TagUtility

public class TagUtility
extends java.lang.Object

This is a holder class that contains static methods that I use in my library. They may or may not be useful for anyone else extending the library.

Version:
$Revision: 1.4 $
Author:
Eric Farng

Method Summary
static java.lang.String addTimeStampToTextArea(java.lang.String text, int origPos)
          Add a timestamp string to a given string.
static java.lang.String appendBeforeExtension(java.lang.String filename, java.lang.String addition)
           
static java.lang.String convertFrameID2_2to2_3(java.lang.String identifier)
           
static java.lang.String convertFrameID2_2to2_4(java.lang.String identifier)
           
static java.lang.String convertFrameID2_3to2_2(java.lang.String identifier)
           
static java.lang.String convertFrameID2_3to2_4(java.lang.String identifier)
           
static java.lang.String convertFrameID2_4to2_2(java.lang.String identifier)
           
static java.lang.String convertFrameID2_4to2_3(java.lang.String identifier)
           
static void copyFile(java.io.File source, java.io.File destination)
          Copy the source file to the destination file.
static java.lang.Object copyObject(java.lang.Object copyObject)
          Unable to instantiate abstract classes, so can't call the copy constructor.
static int findMatchingParenthesis(java.lang.String str, int index)
          return the index of the matching of parenthesis.
static long findNumber(java.lang.String str)
          Find the first whole number that can be parsed from the string
static long findNumber(java.lang.String str, int offset)
          Find the first whole number that can be parsed from the string
static java.lang.String getFrameDescription(java.lang.String identifier)
          Given an ID, get the ID3v2 frame description or the Lyrics3 field description.
static long getWholeNumber(java.lang.Object value)
          Given an object, try to return it as a long.
static boolean isID3v2_2FrameIdentifier(java.lang.String identifier)
          Returns true if the identifier is a valid ID3v2.2 frame identifier
static boolean isID3v2_3FrameIdentifier(java.lang.String identifier)
          Returns true if the identifier is a valid ID3v2.3 frame identifier
static boolean isID3v2_4FrameIdentifier(java.lang.String identifier)
          Returns true if the identifier is a valid ID3v2.4 frame identifier
static boolean isLyrics3v2FieldIdentifier(java.lang.String identifier)
          Returns true if the identifier is a valid Lyrics3v2 frame identifier
static boolean isMatchingParenthesis(java.lang.String str)
          Returns true if the string has matching parenthesis.
static java.lang.String padString(java.lang.String str, int length, char ch, boolean padBefore)
          String formatting function to pad the given string with the given character
static java.lang.String replaceEOLNwithCRLF(java.lang.String text)
          Replace the Unix end of line character with the DOS end of line character.
static java.lang.String replaceWord(java.lang.String source, java.lang.String oldString, java.lang.String newString)
          Search the source string for any occurance of oldString and replaced them all with newString.
static java.lang.String stripChar(java.lang.String str, char ch)
          Remove all occurances of the given character from the string argument.
static java.lang.String toSentenceCase(java.lang.String str, boolean keepUppercase)
          Change the given string into sentence case.
static java.lang.String toTitleCase(java.lang.String str, boolean keepUppercase)
          Change the given string to title case.
static java.lang.String truncate(java.lang.String str, int len)
          truncate a string if it longer than the argument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFrameDescription

public static java.lang.String getFrameDescription(java.lang.String identifier)
Given an ID, get the ID3v2 frame description or the Lyrics3 field description. This takes any kind of ID (four or three letter ID3v2 IDs, and three letter Lyrics3 IDs)

Parameters:
identifier - frame identifier
Returns:
frame description

isID3v2_2FrameIdentifier

public static boolean isID3v2_2FrameIdentifier(java.lang.String identifier)
Returns true if the identifier is a valid ID3v2.2 frame identifier

Parameters:
identifier - string to test
Returns:
true if the identifier is a valid ID3v2.2 frame identifier

isID3v2_3FrameIdentifier

public static boolean isID3v2_3FrameIdentifier(java.lang.String identifier)
Returns true if the identifier is a valid ID3v2.3 frame identifier

Parameters:
identifier - string to test
Returns:
true if the identifier is a valid ID3v2.3 frame identifier

isID3v2_4FrameIdentifier

public static boolean isID3v2_4FrameIdentifier(java.lang.String identifier)
Returns true if the identifier is a valid ID3v2.4 frame identifier

Parameters:
identifier - string to test
Returns:
true if the identifier is a valid ID3v2.4 frame identifier

isLyrics3v2FieldIdentifier

public static boolean isLyrics3v2FieldIdentifier(java.lang.String identifier)
Returns true if the identifier is a valid Lyrics3v2 frame identifier

Parameters:
identifier - string to test
Returns:
true if the identifier is a valid Lyrics3v2 frame identifier

isMatchingParenthesis

public static boolean isMatchingParenthesis(java.lang.String str)
Returns true if the string has matching parenthesis. This method matches all four parenthesis and also enclosed parenthesis.

Parameters:
str - string to test
Returns:
true if the string has matching parenthesis

getWholeNumber

public static long getWholeNumber(java.lang.Object value)
Given an object, 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 explicityly thrown here because it would causes too many other methods to also throw it.

Parameters:
value - object to find long from.
Returns:
long value

addTimeStampToTextArea

public static java.lang.String addTimeStampToTextArea(java.lang.String text,
                                                      int origPos)
Add a timestamp string to a given string. This is used in the GUI and I'm not sure why it is defined here.

Parameters:
text - textarea string to insert to
origPos - current position of the cursor
Returns:
new string to use in the text area

appendBeforeExtension

public static java.lang.String appendBeforeExtension(java.lang.String filename,
                                                     java.lang.String addition)

convertFrameID2_2to2_3

public static java.lang.String convertFrameID2_2to2_3(java.lang.String identifier)

convertFrameID2_2to2_4

public static java.lang.String convertFrameID2_2to2_4(java.lang.String identifier)

convertFrameID2_3to2_2

public static java.lang.String convertFrameID2_3to2_2(java.lang.String identifier)

convertFrameID2_3to2_4

public static java.lang.String convertFrameID2_3to2_4(java.lang.String identifier)

convertFrameID2_4to2_2

public static java.lang.String convertFrameID2_4to2_2(java.lang.String identifier)

convertFrameID2_4to2_3

public static java.lang.String convertFrameID2_4to2_3(java.lang.String identifier)

copyFile

public static void copyFile(java.io.File source,
                            java.io.File destination)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Copy the source file to the destination file. The destination file will be deleted first before copying starts.

Throws:
java.io.FileNotFoundException
java.io.IOException

copyObject

public static java.lang.Object copyObject(java.lang.Object copyObject)
Unable to instantiate abstract classes, so can't call the copy constructor. So find out the instianted class name and call the copy constructor through reflection.


findMatchingParenthesis

public static int findMatchingParenthesis(java.lang.String str,
                                          int index)
return the index of the matching of parenthesis. This will match all four parenthesis and enclosed parenthesis.

Parameters:
str - string to search
index - index of string to start searching. This index should point to the opening parenthesis.
Returns:
index of the matching parenthesis. -1 is returned if none is found, or if the parenthesis are unbalanced.

findNumber

public static long findNumber(java.lang.String str)
                       throws TagException
Find the first whole number that can be parsed from the string

Parameters:
str - string to search
Returns:
first whole number that can be parsed from the string
Throws:
TagException

findNumber

public static long findNumber(java.lang.String str,
                              int offset)
                       throws TagException
Find the first whole number that can be parsed from the string

Parameters:
str - string to search
offset - start seaching from this index
Returns:
first whole number that can be parsed from the string
Throws:
TagException

padString

public static java.lang.String padString(java.lang.String str,
                                         int length,
                                         char ch,
                                         boolean padBefore)
String formatting function to pad the given string with the given character

Parameters:
str - string to pad
length - total length of new string
ch - character to pad the string with
padBefore - if true, add the padding at the start of the string. if false, add the padding at the end of the string.
Returns:
new padded string.

replaceEOLNwithCRLF

public static java.lang.String replaceEOLNwithCRLF(java.lang.String text)
Replace the Unix end of line character with the DOS end of line character.

Parameters:
text - string to search and replace
Returns:
replaced string

replaceWord

public static java.lang.String replaceWord(java.lang.String source,
                                           java.lang.String oldString,
                                           java.lang.String newString)
Search the source string for any occurance of oldString and replaced them all with newString. This searches for the entire word of old string. A blank space is appended to the front and back of oldString


stripChar

public static java.lang.String stripChar(java.lang.String str,
                                         char ch)
Remove all occurances of the given character from the string argument.

Parameters:
str - String to search
ch - character to remove
Returns:
new String without the given charcter

toSentenceCase

public static java.lang.String toSentenceCase(java.lang.String str,
                                              boolean keepUppercase)
Change the given string into sentence case. Sentence case has the first words always capitalized. Any words in TagConstants.upperLowerCase will be capitalized that way. Any other words will be turned lower case.

Parameters:
str - String to modify
keepUppercase - if true, keep a word if it is already all in UPPERCASE
Returns:
new string in sentence case.

toTitleCase

public static java.lang.String toTitleCase(java.lang.String str,
                                           boolean keepUppercase)
Change the given string to title case. The first and last words of the string are always capitilized. Any words in TagConstants.upperLowerCase will be capitalized that way. Any other words will be capitalized.

Parameters:
str - String to modify
keepUppercase - if true, keep a word if it is already all in UPPERCASE
Returns:
new capitlized string.

truncate

public static java.lang.String truncate(java.lang.String str,
                                        int len)
truncate a string if it longer than the argument

Parameters:
str - String to truncate
len - maximum desired length of new string


Copyright (c) 2004 Eric Farng