Mp3dings 
20100427

helliker.id3
Class ID3v2Tag

java.lang.Object
  extended by helliker.id3.ID3v2Tag
All Implemented Interfaces:
ID3Tag

public class ID3v2Tag
extends Object

This class reads and writes id3v2 tags from a file.


Nested Class Summary
static class ID3v2Tag.CorruptHeaderException
           
 
Constructor Summary
ID3v2Tag(File mp3)
          Create an id3v2 tag bound to the file provided as a parameter.
 
Method Summary
 void copyFrom(ID3Tag tag)
          Copies information from the ID3Tag parameter and inserts it into this tag.
 APICImage getAttachedPicture()
           
 byte[] getFrameData(String id)
          Returns the data found in the frame specified by the id.
 String getFrameDataString(String id)
          Returns the textual information contained in the frame specified by the id.
 int getTotalWrittenTagSize()
           
 void removeFrame(String id)
          Remove the frame with the specified id from the file.
 void removeTag()
          Remove an existing id3v2 tag from the file passed to the constructor.
 void removeTag(boolean forceMpegOffset)
          Removes this tag from the file it is bound to.
 void setAttachedPicture(APICImage pic)
           
 void setCommentFrame(String description, String comment)
          Set the data contained in the comments frame (COMM).
 void setTextFrame(String id, String data)
          Set the data contained in a text frame.
 void setURLFrame(String id, String data)
          Set the data contained in a URL frame.
 void setUserDefinedTextFrame(String description, String value)
          Sets the data contained in the user defined text frame (TXXX).
 void setUserDefinedURLFrame(String description, String value)
          Sets the data contained in the user defined url frame (WXXX).
 boolean tagExists()
          Returns true if an id3v2 tag exists in the file that was passed to the constructor and false otherwise
 String toString()
          Return a string representation of this object.
 void updateFrameData(String id, byte[] data)
          Updates the data for the frame specified by id.
 void writeTag()
          Saves all data in this tag to the file it is bound to.
 void writeTag(boolean forceMpegOffset)
          Saves all the information in the tag to the file passed to the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ID3v2Tag

public ID3v2Tag(File mp3)
         throws IOException,
                ID3v2FormatException
Create an id3v2 tag bound to the file provided as a parameter. If a tag exists in the file already, then all the information in the tag will be extracted. If a tag doesn't exist, then this is the file that will be written to when the writeTag method is called.

Parameters:
mp3 - the file to write/read the the tag information to/from
Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs
ID3v2FormatException - if an exisiting id3v2 tag isn't correct
Method Detail

writeTag

public void writeTag()
              throws IOException
Description copied from interface: ID3Tag
Saves all data in this tag to the file it is bound to.

Throws:
IOException - if an error occurs

writeTag

public void writeTag(boolean forceMpegOffset)
              throws IOException
Saves all the information in the tag to the file passed to the constructor. If a tag doesn't exist, a tag is prepended to the file. If the new tag size is less than the old size + padding, then the old tag and part of the old padding will be overwritten. Otherwise, a new tag will be prepended to the file.
This method fixes incorrect header size information where this can be done without any risk of data loss.

Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs

removeTag

public void removeTag()
               throws IOException
Remove an existing id3v2 tag from the file passed to the constructor.

Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs

removeTag

public void removeTag(boolean forceMpegOffset)
               throws IOException
Description copied from interface: ID3Tag
Removes this tag from the file it is bound to.

Throws:
IOException - if an error occurs

tagExists

public boolean tagExists()
Returns true if an id3v2 tag exists in the file that was passed to the constructor and false otherwise

Returns:
true if an id3v2 tag exists in the file passed to the ctor

getTotalWrittenTagSize

public int getTotalWrittenTagSize()

toString

public String toString()
Return a string representation of this object. This includes all data contained in all parts of this tag.

Overrides:
toString in class Object
Returns:
a string representation of this object

copyFrom

public void copyFrom(ID3Tag tag)
Copies information from the ID3Tag parameter and inserts it into this tag. Previous data will be overwritten. [NOT IMPLEMENTED]

Parameters:
tag - the tag to copy from

setTextFrame

public void setTextFrame(String id,
                         String data)
Set the data contained in a text frame. This includes all frames with an id that starts with 'T' but excludes "TXXX". If an improper id is passed, then nothing will happen.

Parameters:
id - the id of the frame to set the data for
data - the data for the frame

setURLFrame

public void setURLFrame(String id,
                        String data)
Set the data contained in a URL frame. This includes all frames with an id that starts with 'W' but excludes "WXXX". If an improper id is passed, then nothing will happen.

Parameters:
id - the id of the frame to set the data for
data - the data for the frame

setUserDefinedTextFrame

public void setUserDefinedTextFrame(String description,
                                    String value)
Sets the data contained in the user defined text frame (TXXX).

Parameters:
description - a description of the data
value - the data for the frame

setUserDefinedURLFrame

public void setUserDefinedURLFrame(String description,
                                   String value)
Sets the data contained in the user defined url frame (WXXX).

Parameters:
description - a description of the url
value - the url for the frame

setCommentFrame

public void setCommentFrame(String description,
                            String comment)
Set the data contained in the comments frame (COMM).

Parameters:
description - a description of the comment
comment - the comment

removeFrame

public void removeFrame(String id)
Remove the frame with the specified id from the file. If there is no frame with that id nothing will happen.

Parameters:
id - the id of the frame to remove

updateFrameData

public void updateFrameData(String id,
                            byte[] data)
Updates the data for the frame specified by id. If no frame exists for the id specified, a new frame with that id is created.

Parameters:
id - the id of the frame to update
data - the data for the frame

getFrameDataString

public String getFrameDataString(String id)
                          throws ID3v2FormatException
Returns the textual information contained in the frame specified by the id. Not every type of frame has textual information. If an id is specified that will not work, the empty string is returned.

Parameters:
id - the id of the frame to get text from
Returns:
the text information contained in the frame
Throws:
ID3v2FormatException - if an error is encountered parsing data

getAttachedPicture

public APICImage getAttachedPicture()
                             throws ID3v2FormatException
Throws:
ID3v2FormatException

setAttachedPicture

public void setAttachedPicture(APICImage pic)

getFrameData

public byte[] getFrameData(String id)
Returns the data found in the frame specified by the id. If the frame doesn't exist, then a zero length array is returned.

Parameters:
id - the id of the frame to get the data from
Returns:
the data found in the frame

Mp3dings 
20100427