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

FieldFrameBodyLYR

public class FieldFrameBodyLYR extends AbstractLyrics3v2FieldFrameBody
author
: Paul Taylor
author
: Eric Farng Version @version:$Id: FieldFrameBodyLYR.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 ArrayList
lines
Constructors Summary
public FieldFrameBodyLYR()
Creates a new FieldBodyLYR datatype.


              
     
    
    
public FieldFrameBodyLYR(FieldFrameBodyLYR copyObject)

        super(copyObject);

        Lyrics3Line old;

        for (int i = 0; i < copyObject.lines.size(); i++)
        {
            old = copyObject.lines.get(i);
            this.lines.add(new Lyrics3Line(old));
        }
    
public FieldFrameBodyLYR(String line)
Creates a new FieldBodyLYR datatype.

param
line

        readString(line);
    
public FieldFrameBodyLYR(org.jaudiotagger.tag.id3.framebody.FrameBodySYLT sync)
Creates a new FieldBodyLYR datatype.

param
sync

        addLyric(sync);
    
public FieldFrameBodyLYR(org.jaudiotagger.tag.id3.framebody.FrameBodyUSLT unsync)
Creates a new FieldBodyLYR datatype.

param
unsync

        addLyric(unsync);
    
public FieldFrameBodyLYR(ByteBuffer byteBuffer)
Creates a new FieldBodyLYR datatype.

param
byteBuffer
throws
org.jaudiotagger.tag.InvalidTagException


        this.read(byteBuffer);

    
Methods Summary
public voidaddLyric(org.jaudiotagger.tag.id3.framebody.FrameBodySYLT sync)

param
sync

        // SYLT frames are made of individual lines
        Iterator<ID3v2LyricLine> iterator = sync.iterator();
        Lyrics3Line newLine;
        ID3v2LyricLine currentLine;
        Lyrics3TimeStamp timeStamp;
        HashMap<String, Lyrics3Line> lineMap = new HashMap<String, Lyrics3Line>();

        while (iterator.hasNext())
        {
            currentLine = iterator.next();

            // createField copy to use in new tag
            currentLine = new ID3v2LyricLine(currentLine);
            timeStamp = new Lyrics3TimeStamp("Time Stamp", this);
            timeStamp.setTimeStamp(currentLine.getTimeStamp(), (byte) sync.getTimeStampFormat());

            if (lineMap.containsKey(currentLine.getText()))
            {
                newLine = lineMap.get(currentLine.getText());
                newLine.addTimeStamp(timeStamp);
            }
            else
            {
                newLine = new Lyrics3Line("Lyric Line", this);
                newLine.setLyric(currentLine);
                newLine.setTimeStamp(timeStamp);
                lineMap.put(currentLine.getText(), newLine);
                lines.add(newLine);
            }
        }
    
public voidaddLyric(org.jaudiotagger.tag.id3.framebody.FrameBodyUSLT unsync)

param
unsync

        // USLT frames are just long text string;
        Lyrics3Line line = new Lyrics3Line("Lyric Line", this);
        line.setLyric(unsync.getLyric());
        lines.add(line);
    
public booleanequals(java.lang.Object obj)

param
obj
return

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

        FieldFrameBodyLYR object = (FieldFrameBodyLYR) obj;

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

    
public java.lang.StringgetIdentifier()

return

        return "LYR";
    
public java.lang.StringgetLyric()

return

        return writeString();
    
public intgetSize()

return

        int size = 0;
        Lyrics3Line line;

        for (Object line1 : lines)
        {
            line = (Lyrics3Line) line1;
            size += (line.getSize() + 2);
        }

        return size;

        //return size - 2; // cut off the last crlf pair
    
public booleanhasTimeStamp()

return

        boolean present = false;

        for (Object line : lines)
        {
            if (((Lyrics3Line) line).hasTimeStamp())
            {
                present = true;
            }
        }

        return present;
    
public booleanisSubsetOf(java.lang.Object obj)

param
obj
return

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

        ArrayList<Lyrics3Line> superset = ((FieldFrameBodyLYR) obj).lines;

        for (Object line : lines)
        {
            if (!superset.contains(line))
            {
                return false;
            }
        }

        return super.isSubsetOf(obj);
    
public java.util.Iteratoriterator()

return

        return lines.iterator();
    
public voidread(java.nio.ByteBuffer byteBuffer)

        String lineString;

        byte[] buffer = new byte[5];

        // read the 5 character size
        byteBuffer.get(buffer, 0, 5);

        int size = Integer.parseInt(new String(buffer, 0, 5));

        if ((size == 0) && (!TagOptionSingleton.getInstance().isLyrics3KeepEmptyFieldIfRead()))
        {
            throw new InvalidTagException("Lyircs3v2 Field has size of zero.");
        }

        buffer = new byte[size];

        // read the SIZE length description
        byteBuffer.get(buffer);
        lineString = new String(buffer);
        readString(lineString);
    
private voidreadString(java.lang.String lineString)

param
lineString

        // now readString each line and put in the vector;
        String token;
        int offset = 0;
        int delim = lineString.indexOf(Lyrics3v2Fields.CRLF);
        lines = new ArrayList<Lyrics3Line>();

        Lyrics3Line line;

        while (delim >= 0)
        {
            token = lineString.substring(offset, delim);
            line = new Lyrics3Line("Lyric Line", this);
            line.setLyric(token);
            lines.add(line);
            offset = delim + Lyrics3v2Fields.CRLF.length();
            delim = lineString.indexOf(Lyrics3v2Fields.CRLF, offset);
        }

        if (offset < lineString.length())
        {
            token = lineString.substring(offset);
            line = new Lyrics3Line("Lyric Line", this);
            line.setLyric(token);
            lines.add(line);
        }
    
public voidsetLyric(java.lang.String str)

param
str

        readString(str);
    
protected voidsetupObjectList()
TODO


    
public java.lang.StringtoString()

return

        String str = getIdentifier() + " : ";

        for (Object line : lines)
        {
            str += line.toString();
        }

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

param
file
throws
java.io.IOException

        int size;
        int offset = 0;
        byte[] buffer = new byte[5];
        String str;

        size = getSize();
        str = Integer.toString(size);

        for (int i = 0; i < (5 - str.length()); i++)
        {
            buffer[i] = (byte) '0";
        }

        offset += (5 - str.length());

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

        offset += str.length();
        file.write(buffer, 0, 5);

        if (size > 0)
        {
            str = writeString();
            buffer = new byte[str.length()];

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

            file.write(buffer);
        }
    
private java.lang.StringwriteString()

return

        Lyrics3Line line;
        String str = "";

        for (Object line1 : lines)
        {
            line = (Lyrics3Line) line1;
            str += (line.writeString() + Lyrics3v2Fields.CRLF);
        }

        return str;

        //return str.substring(0,str.length()-2); // cut off the last CRLF pair