helliker.id3
Class ID3v1Tag

java.lang.Object
  extended byhelliker.id3.ID3v1Tag
All Implemented Interfaces:
ID3Tag

public class ID3v1Tag
extends java.lang.Object
implements ID3Tag


Field Summary
private  java.lang.String album
           
private  int ALBUM_SIZE
           
private  java.lang.String artist
           
private  int ARTIST_SIZE
           
private  java.lang.String comment
           
private  int COMMENT_SIZE
           
private  int genre
           
private  int GENRE_LOCATION
           
private  boolean headerExists
           
private  int MAX_GENRE
           
private  int MAX_TRACK
           
private  java.io.File mp3
           
private  int TAG_SIZE
           
private  java.lang.String TAG_START
           
private  java.lang.String title
           
private  int TITLE_SIZE
           
private  int track
           
private  int TRACK_LOCATION
           
private  java.lang.String year
           
private  int YEAR_SIZE
           
 
Constructor Summary
ID3v1Tag(java.io.File mp3)
          Create an id3v1tag from the file specified.
 
Method Summary
private  boolean checkHeader(java.io.RandomAccessFile raf)
          Checks whether a header for the id3 tag exists yet
private  java.lang.String chopSubstring(java.lang.String s, int start, int end)
          Finds the substring of the String parameter but ends the string with the first null byte encountered.
 void copyFrom(ID3Tag tag)
          Copies information from the ID3Tag parameter and inserts it into this tag.
 java.lang.String getAlbum()
          Return the album field of the tag
 java.lang.String getArtist()
          Return the artist field of the tag
 byte[] getBytes()
          Returns a binary representation of this id3v1 tag.
 java.lang.String getComment()
          Return the comment field of the tag
private  byte[] getFieldBytes(java.lang.String str, int length)
          Converts a string to an array of bytes with the length specified
 int getGenre()
          Return the genre field of the tag
 java.lang.String getGenreString()
          Return the genre name based on the ID3/Nullsoft standards.
 int getSize()
          Return the size in bytes of the tag.
 java.lang.String getTitle()
          Return the title field of the tag
 int getTrack()
          Return the track field of the tag
 java.lang.String getYear()
          Return the year field of the tag
private  void readTag(java.io.RandomAccessFile raf)
          Reads the data from the id3v1 tag
 void removeTag()
          Removes the id3v1 tag from the file specified in the constructor
 void setAlbum(java.lang.String newAlbum)
          Set the album field of the tag.
 void setArtist(java.lang.String newArtist)
          Set the artist field of the tag.
 void setComment(java.lang.String newComment)
          Set the comment field of the tag.
 void setGenre(int newGenre)
          Set the genre field of the tag.
 boolean setGenreString(java.lang.String str)
          Attempt to set the genre value of this tag from the string specified.
 void setTitle(java.lang.String newTitle)
          Set the title field of the tag.
 void setTrack(int newTrack)
          Set the track field of the tag.
 void setYear(java.lang.String newYear)
          Set the year field of the tag.
 boolean tagExists()
          Checks if a tag exists
 java.lang.String toString()
          Returns a String representation of this object.
 void writeTag()
          Writes the information in this tag to the file specified in the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TAG_SIZE

private final int TAG_SIZE
See Also:
Constant Field Values

TITLE_SIZE

private final int TITLE_SIZE
See Also:
Constant Field Values

ARTIST_SIZE

private final int ARTIST_SIZE
See Also:
Constant Field Values

ALBUM_SIZE

private final int ALBUM_SIZE
See Also:
Constant Field Values

YEAR_SIZE

private final int YEAR_SIZE
See Also:
Constant Field Values

COMMENT_SIZE

private final int COMMENT_SIZE
See Also:
Constant Field Values

TRACK_LOCATION

private final int TRACK_LOCATION
See Also:
Constant Field Values

GENRE_LOCATION

private final int GENRE_LOCATION
See Also:
Constant Field Values

MAX_GENRE

private final int MAX_GENRE
See Also:
Constant Field Values

MAX_TRACK

private final int MAX_TRACK
See Also:
Constant Field Values

TAG_START

private final java.lang.String TAG_START
See Also:
Constant Field Values

mp3

private java.io.File mp3

headerExists

private boolean headerExists

title

private java.lang.String title

artist

private java.lang.String artist

album

private java.lang.String album

year

private java.lang.String year

comment

private java.lang.String comment

genre

private int genre

track

private int track
Constructor Detail

ID3v1Tag

public ID3v1Tag(java.io.File mp3)
         throws java.io.FileNotFoundException,
                java.io.IOException
Create an id3v1tag from the file specified. If the file contains a tag, the information is automatically extracted.

Parameters:
mp3 - the file to read/write the tag to
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs
Method Detail

checkHeader

private boolean checkHeader(java.io.RandomAccessFile raf)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Checks whether a header for the id3 tag exists yet

Parameters:
raf - the open file to read from
Returns:
true if a tag is found
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

readTag

private void readTag(java.io.RandomAccessFile raf)
              throws java.io.FileNotFoundException,
                     java.io.IOException
Reads the data from the id3v1 tag

Parameters:
raf - the open file to read from
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

chopSubstring

private java.lang.String chopSubstring(java.lang.String s,
                                       int start,
                                       int end)
Finds the substring of the String parameter but ends the string with the first null byte encountered.

Parameters:
s - the string chop
start - where to start the string
end - where to end the string if a null byte isn't found
Returns:
the chopped string

writeTag

public void writeTag()
              throws java.io.FileNotFoundException,
                     java.io.IOException
Writes the information in this tag to the file specified in the constructor. If a tag does not exist, one will be created. If a tag already exists, it will be overwritten.

Specified by:
writeTag in interface ID3Tag
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

getBytes

public byte[] getBytes()
Returns a binary representation of this id3v1 tag. It is in the correct format according to the id3v1.1 specifications.

Specified by:
getBytes in interface ID3Tag
Returns:
a binary representation of this id3v1 tag

getFieldBytes

private byte[] getFieldBytes(java.lang.String str,
                             int length)
                      throws java.io.UnsupportedEncodingException
Converts a string to an array of bytes with the length specified

Parameters:
str - the string to convert
length - the size of the byte array
Returns:
the array of bytes converted from the string
Throws:
java.io.UnsupportedEncodingException

removeTag

public void removeTag()
               throws java.io.FileNotFoundException,
                      java.io.IOException
Removes the id3v1 tag from the file specified in the constructor

Specified by:
removeTag in interface ID3Tag
Returns:
true if the tag was removed successfully
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

getGenreString

public java.lang.String getGenreString()
Return the genre name based on the ID3/Nullsoft standards. If the genre value is not valid, null is returned.

Returns:
return the genre name or null if the genre value is not valid

setGenreString

public boolean setGenreString(java.lang.String str)
Attempt to set the genre value of this tag from the string specified. The value returned is based on the ID3/Nullsoft standards. Returns true if a match is found in the table and false otherwise.

Parameters:
str - the string value of the genre to attempt to set
Returns:
true if a match is found, false otherwise

tagExists

public boolean tagExists()
Checks if a tag exists

Returns:
true if a tag exists

getTitle

public java.lang.String getTitle()
Return the title field of the tag

Returns:
the title field of the tag

setTitle

public void setTitle(java.lang.String newTitle)
Set the title field of the tag. The maximum size of the String is 30. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newTitle - the title for the tag

getArtist

public java.lang.String getArtist()
Return the artist field of the tag

Returns:
the artist field of the tag

setArtist

public void setArtist(java.lang.String newArtist)
Set the artist field of the tag. The maximum size of the String is 30. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newArtist - the artist for the tag

getAlbum

public java.lang.String getAlbum()
Return the album field of the tag

Returns:
the album field of the tag

setAlbum

public void setAlbum(java.lang.String newAlbum)
Set the album field of the tag. The maximum size of the String is 30. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newAlbum - the album for the tag

getYear

public java.lang.String getYear()
Return the year field of the tag

Returns:
the year field of the tag

setYear

public void setYear(java.lang.String newYear)
Set the year field of the tag. The maximum size of the String is 4. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newYear - the year for the tag

getComment

public java.lang.String getComment()
Return the comment field of the tag

Returns:
the comment field of the tag

setComment

public void setComment(java.lang.String newComment)
Set the comment field of the tag. The maximum size of the String is 30. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newComment - the comment of the tag

getTrack

public int getTrack()
Return the track field of the tag

Returns:
the track field of the tag

setTrack

public void setTrack(int newTrack)
Set the track field of the tag. The track number has to be between 0 and 255. If it is not, nothing will happen.

Parameters:
newTrack - the track of the tag

getGenre

public int getGenre()
Return the genre field of the tag

Returns:
the genre field of the tag

setGenre

public void setGenre(int newGenre)
              throws ID3FieldDataException
Set the genre field of the tag. This probably should not be greater than 115, but supports values from 0-255.

Parameters:
newGenre - the genre of the tag
Throws:
ID3FieldDataException - if the value supplie is invalid

getSize

public int getSize()
Return the size in bytes of the tag. This returns 128 if the tag exists and 0 otherwise.

Returns:
the size of the tag in bytes

toString

public java.lang.String toString()
Returns a String representation of this object. Contains all information within the tag.

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]

Specified by:
copyFrom in interface ID3Tag
Parameters:
tag - the tag to copy from


Copyright © 2004 NeurosDBM Dev Team All Rights Reserved.