Methods Summary |
---|
public java.lang.String | getAlbum()Get the name of the album from which the recording comes.
return m_sAlbum;
|
public java.lang.String | getArtist()Get the artist of the recording.
return m_sArtist;
|
public java.lang.String | getComment()Get the comment.
return m_sComment;
|
public org.blinkenlights.jid3.v1.ID3V1Tag$Genre | getGenre()Get the genre of the recording.
return m_oGenre;
|
public java.lang.String | getTitle()Get the title of the recording.
return m_sTitle;
|
public java.lang.String | getYear()Get the year in which the recording was made.
return m_sYear;
|
private static int | indexOfFirstNull(byte[] abyString)Utility method to find the index of the first zero byte in a byte array.
for (int i=0; i < abyString.length; i++)
{
if (abyString[i] == 0)
{
return i;
}
}
return abyString.length;
|
public static org.blinkenlights.jid3.v1.ID3V1Tag | read(java.io.InputStream oIS)Read an ID3 V1 tag from an input stream.
try
{
// title (30 bytes)
byte[] abyTitle = new byte[30];
if (oIS.read(abyTitle) != 30)
{
throw new ID3Exception("Unexpected EOF while reading title.");
}
String sTitle = new String(abyTitle, 0, indexOfFirstNull(abyTitle));
// artist (30 bytes)
byte[] abyArtist = new byte[30];
if (oIS.read(abyArtist) != 30)
{
throw new ID3Exception("Unexpected EOF while reading artist.");
}
String sArtist = new String(abyArtist, 0, indexOfFirstNull(abyArtist));
// album (30 bytes)
byte[] abyAlbum = new byte[30];
if (oIS.read(abyAlbum) != 30)
{
throw new ID3Exception("Unexpected EOF while reading album.");
}
String sAlbum = new String(abyAlbum, 0, indexOfFirstNull(abyAlbum));
// year (4 bytes)
byte[] abyYear = new byte[4];
if (oIS.read(abyYear) != 4)
{
throw new ID3Exception("Unexpected EOF while reading year.");
}
String sYear = new String(abyYear, 0, indexOfFirstNull(abyYear));
// comment (30 bytes) possibly including an album track # as the last byte
String sComment;
boolean bHasTrackNum;
int iTrackNum = -1;
byte[] abyTemp = new byte[30];
if (oIS.read(abyTemp) != 30)
{
throw new ID3Exception("Unexpected EOF while reading comment.");
}
if ((abyTemp[28] == 0) && (abyTemp[29] != 0))
{
// this is a v1.1 tag with comment and track number
byte[] abyComment = new byte[29];
System.arraycopy(abyTemp, 0, abyComment, 0, 29);
sComment = new String(abyComment, 0, indexOfFirstNull(abyComment));
iTrackNum = abyTemp[29] & 0xff;
bHasTrackNum = true;
}
else
{
// this is just a comment
sComment = new String(abyTemp, 0, indexOfFirstNull(abyTemp));
bHasTrackNum = false;
}
// genre
int iGenre = oIS.read();
// create appropriate ID3V1Tag object and set properties
ID3V1Tag oID3V1Tag = null;
if (bHasTrackNum)
{
// v1.1 tag
oID3V1Tag = new ID3V1_1Tag();
((ID3V1_1Tag)oID3V1Tag).setAlbumTrack(iTrackNum);
}
else
{
// v1.0 tag
oID3V1Tag = new ID3V1_0Tag();
}
oID3V1Tag.setTitle(sTitle);
oID3V1Tag.setArtist(sArtist);
oID3V1Tag.setAlbum(sAlbum);
oID3V1Tag.setYear(sYear);
oID3V1Tag.setComment(sComment);
try
{
oID3V1Tag.setGenre(Genre.lookupGenre(iGenre));
}
catch (ID3Exception e)
{
if (ID3Tag.usingStrict())
{
throw e;
}
else
{
oID3V1Tag.setGenre(new Genre((byte)iGenre, "Unknown"));
}
}
return oID3V1Tag;
}
catch (Exception e)
{
throw new ID3Exception(e);
}
|
public void | setAlbum(java.lang.String sAlbum)Set the name of the album from which the recording comes.
if (sAlbum.length() > 30)
{
sAlbum = sAlbum.substring(0, 30);
}
m_sAlbum = sAlbum;
|
public void | setArtist(java.lang.String sArtist)Set the artist for the recording.
if (sArtist.length() > 30)
{
sArtist = sArtist.substring(0, 30);
}
m_sArtist = sArtist;
|
public abstract void | setComment(java.lang.String sComment)Set the comment field.
|
public void | setGenre(org.blinkenlights.jid3.v1.ID3V1Tag$Genre oGenre)Set the genre of the recording, using one of the predefined genre values.
m_oGenre = oGenre;
|
public void | setTitle(java.lang.String sTitle)Set the title of the recording.
if (sTitle.length() > 30)
{
sTitle = sTitle.substring(0, 30);
}
m_sTitle = sTitle;
|
public void | setYear(java.lang.String sYear)Set the year in which the recording was made.
if (sYear.length() > 4)
{
sYear = sYear.substring(0, 4);
}
m_sYear = sYear;
|
public java.lang.String | toString()
// lookup genre string, if possible (print byte value otherwise)
String sGenre = null;
try
{
sGenre = ID3V1Tag.Genre.lookupGenre(m_oGenre.m_byGenre).toString();
}
catch (Exception e)
{
sGenre = Byte.toString(m_oGenre.m_byGenre);
}
return "SongTitle = [" + m_sTitle + "]\n" +
"Artist = [" + m_sArtist + "]\n" +
"Album = [" + m_sAlbum + "]\n" +
"Year = [" + m_sYear + "]\n" +
"Comment = [" + m_sComment + "]\n" +
"Genre = " + sGenre; //m_oGenre.m_byGenre;
|
public abstract void | write(java.io.OutputStream oOS)Write tag to output stream.
|