FileDocCategorySizeDatePackage
Lyrics3v1.javaAPI DocJaudiotagger 2.0.47927Wed Mar 30 16:12:08 BST 2011org.jaudiotagger.tag.lyrics3

Lyrics3v1

public class Lyrics3v1 extends AbstractLyrics3
author
: Paul Taylor
author
: Eric Farng Version @version:$Id: Lyrics3v1.java 836 2009-11-12 15:44:07Z paultaylor $ MusicTag Copyright (C)2003,2004 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Description:

Fields Summary
private String
lyric
Constructors Summary
public Lyrics3v1()
Creates a new Lyrics3v1 datatype.


              
     
    
    
public Lyrics3v1(Lyrics3v1 copyObject)

        super(copyObject);
        this.lyric = copyObject.lyric;
    
public Lyrics3v1(org.jaudiotagger.tag.id3.AbstractTag mp3Tag)

        if (mp3Tag != null)
        {
            Lyrics3v2 lyricTag;

            if (mp3Tag instanceof Lyrics3v1)
            {
                throw new UnsupportedOperationException("Copy Constructor not called. Please type cast the argument");
            }
            else if (mp3Tag instanceof Lyrics3v2)
            {
                lyricTag = (Lyrics3v2) mp3Tag;
            }
            else
            {
                lyricTag = new Lyrics3v2(mp3Tag);
            }

            FieldFrameBodyLYR lyricField;
            lyricField = (FieldFrameBodyLYR) lyricTag.getField("LYR").getBody();
            this.lyric = lyricField.getLyric();
        }
    
public Lyrics3v1(ByteBuffer byteBuffer)
Creates a new Lyrics3v1 datatype.

param
file
throws
TagNotFoundException
throws
java.io.IOException
param
byteBuffer

        try
        {
            this.read(byteBuffer);
        }
        catch (TagException e)
        {
            e.printStackTrace();
        }
    
Methods Summary
public booleanequals(java.lang.Object obj)

param
obj
return

        if (!(obj instanceof Lyrics3v1))
        {
            return false;
        }

        Lyrics3v1 object = (Lyrics3v1) obj;

        return this.lyric.equals(object.lyric) && super.equals(obj);

    
public java.lang.StringgetIdentifier()

return

        return "Lyrics3v1.00";
    
public java.lang.StringgetLyric()

return

        return lyric;
    
public intgetSize()

return

        return "LYRICSBEGIN".length() + lyric.length() + "LYRICSEND".length();
    
public booleanisSubsetOf(java.lang.Object obj)

param
obj
return

        return (obj instanceof Lyrics3v1) && (((Lyrics3v1) obj).lyric.contains(this.lyric));

    
public java.util.Iteratoriterator()

return
throws
java.lang.UnsupportedOperationException

        /**
         * @todo Implement this org.jaudiotagger.tag.AbstractMP3Tag abstract method
         */
        throw new java.lang.UnsupportedOperationException("Method iterator() not yet implemented.");
    
public voidread(java.nio.ByteBuffer byteBuffer)

param
byteBuffer
throws
TagNotFoundException
throws
IOException

        byte[] buffer = new byte[5100 + 9 + 11];
        String lyricBuffer;

        if (!seek(byteBuffer))
        {
            throw new TagNotFoundException("ID3v1 tag not found");
        }

        byteBuffer.get(buffer);
        lyricBuffer = new String(buffer);

        lyric = lyricBuffer.substring(0, lyricBuffer.indexOf("LYRICSEND"));
    
public booleanseek(java.nio.ByteBuffer byteBuffer)
TODO implement

param
byteBuffer
return
throws
IOException

        return false;
    
public booleanseek(java.io.RandomAccessFile file)

param
file
return
throws
IOException

        byte[] buffer = new byte[5100 + 9 + 11];
        String lyricsEnd;
        String lyricsStart;
        long offset;

        // check right before the ID3 1.0 tag for the lyrics tag
        file.seek(file.length() - 128 - 9);
        file.read(buffer, 0, 9);
        lyricsEnd = new String(buffer, 0, 9);

        if (lyricsEnd.equals("LYRICSEND"))
        {
            offset = file.getFilePointer();
        }
        else
        {
            // check the end of the file for a lyrics tag incase an ID3
            // tag wasn't placed after it.
            file.seek(file.length() - 9);
            file.read(buffer, 0, 9);
            lyricsEnd = new String(buffer, 0, 9);

            if (lyricsEnd.equals("LYRICSEND"))
            {
                offset = file.getFilePointer();
            }
            else
            {
                return false;
            }
        }

        // the tag can at most only be 5100 bytes
        offset -= (5100 + 9 + 11);
        file.seek(offset);
        file.read(buffer);
        lyricsStart = new String(buffer);

        // search for the tag
        int i = lyricsStart.indexOf("LYRICSBEGIN");

        if (i == -1)
        {
            return false;
        }

        file.seek(offset + i + 11);

        return true;
    
public voidsetLyric(java.lang.String lyric)

param
lyric

        this.lyric = ID3Tags.truncate(lyric, 5100);
    
public java.lang.StringtoString()

return

        String str = getIdentifier() + " " + this.getSize() + "\n";

        return str + lyric;
    
public voidwrite(java.io.RandomAccessFile file)

param
file
throws
IOException

        String str;
        int offset;
        byte[] buffer;
        ID3v1Tag id3v1tag;

        id3v1tag = null;

        delete(file);
        file.seek(file.length());

        buffer = new byte[lyric.length() + 11 + 9];

        str = "LYRICSBEGIN";

        for (int i = 0; i < str.length(); i++)
        {
            buffer[i] = (byte) str.charAt(i);
        }

        offset = str.length();

        str = ID3Tags.truncate(lyric, 5100);

        for (int i = 0; i < str.length(); i++)
        {
            buffer[i + offset] = (byte) str.charAt(i);
        }

        offset += str.length();

        str = "LYRICSEND";

        for (int i = 0; i < str.length(); i++)
        {
            buffer[i + offset] = (byte) str.charAt(i);
        }

        offset += str.length();

        file.write(buffer, 0, offset);

        if (id3v1tag != null)
        {
            id3v1tag.write(file);
        }