Lyrics3v2public class Lyrics3v2 extends AbstractLyrics3
Fields Summary |
---|
private HashMap | fieldMap |
Constructors Summary |
---|
public Lyrics3v2()Creates a new Lyrics3v2 datatype.
| public Lyrics3v2(Lyrics3v2 copyObject)
super(copyObject);
Iterator<String> iterator = copyObject.fieldMap.keySet().iterator();
String oldIdentifier;
String newIdentifier;
Lyrics3v2Field newObject;
while (iterator.hasNext())
{
oldIdentifier = iterator.next();
newIdentifier = oldIdentifier;
newObject = new Lyrics3v2Field(copyObject.fieldMap.get(newIdentifier));
fieldMap.put(newIdentifier, newObject);
}
| public Lyrics3v2(org.jaudiotagger.tag.id3.AbstractTag mp3tag)Creates a new Lyrics3v2 datatype.
if (mp3tag != null)
{
// upgrade the tag to lyrics3v2
if (mp3tag instanceof Lyrics3v2)
{
throw new UnsupportedOperationException("Copy Constructor not called. Please type cast the argument");
}
else if (mp3tag instanceof Lyrics3v1)
{
Lyrics3v1 lyricOld = (Lyrics3v1) mp3tag;
Lyrics3v2Field newField;
newField = new Lyrics3v2Field(new FieldFrameBodyLYR(lyricOld.getLyric()));
fieldMap.put(newField.getIdentifier(), newField);
}
else
{
Lyrics3v2Field newField;
Iterator<AbstractID3v2Frame> iterator;
iterator = (new ID3v24Tag(mp3tag)).iterator();
while (iterator.hasNext())
{
try
{
newField = new Lyrics3v2Field(iterator.next());
if (newField != null)
{
fieldMap.put(newField.getIdentifier(), newField);
}
}
catch (TagException ex)
{
//invalid frame to createField lyrics3 field. ignore and keep going
}
}
}
}
| public Lyrics3v2(ByteBuffer byteBuffer)Creates a new Lyrics3v2 datatype.
try
{
this.read(byteBuffer);
}
catch (TagException e)
{
e.printStackTrace();
}
|
Methods Summary |
---|
public boolean | equals(java.lang.Object obj)
if (!(obj instanceof Lyrics3v2))
{
return false;
}
Lyrics3v2 object = (Lyrics3v2) obj;
return this.fieldMap.equals(object.fieldMap) && super.equals(obj);
| public Lyrics3v2Field | getField(java.lang.String identifier)Gets the value of the frame identified by identifier
return fieldMap.get(identifier);
| public int | getFieldCount()
return fieldMap.size();
| public java.lang.String | getIdentifier()
return "Lyrics3v2.00";
| public int | getSize()
int size = 0;
Iterator<Lyrics3v2Field> iterator = fieldMap.values().iterator();
Lyrics3v2Field field;
while (iterator.hasNext())
{
field = iterator.next();
size += field.getSize();
}
// include LYRICSBEGIN, but not 6 char size or LYRICSEND
return 11 + size;
| public boolean | hasField(java.lang.String identifier)
return fieldMap.containsKey(identifier);
| public java.util.Iterator | iterator()
return fieldMap.values().iterator();
| public void | read(java.nio.ByteBuffer byteBuffer)
long filePointer;
int lyricSize;
if (seek(byteBuffer))
{
lyricSize = seekSize(byteBuffer);
}
else
{
throw new TagNotFoundException("Lyrics3v2.00 Tag Not Found");
}
// reset file pointer to the beginning of the tag;
seek(byteBuffer);
filePointer = byteBuffer.position();
fieldMap = new HashMap<String, Lyrics3v2Field>();
Lyrics3v2Field lyric;
// read each of the fields
while ((byteBuffer.position()) < (lyricSize - 11))
{
try
{
lyric = new Lyrics3v2Field(byteBuffer);
setField(lyric);
}
catch (InvalidTagException ex)
{
// keep reading until we're done
}
}
| public void | removeField(java.lang.String identifier)
fieldMap.remove(identifier);
| public boolean | seek(java.nio.ByteBuffer byteBuffer)TODO implement
return false;
| public boolean | seek(java.io.RandomAccessFile file)
byte[] buffer = new byte[11];
String lyricEnd;
String lyricStart;
long filePointer;
long lyricSize;
// check right before the ID3 1.0 tag for the lyrics tag
file.seek(file.length() - 128 - 9);
file.read(buffer, 0, 9);
lyricEnd = new String(buffer, 0, 9);
if (lyricEnd.equals("LYRICS200"))
{
filePointer = 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);
lyricEnd = new String(buffer, 0, 9);
if (lyricEnd.equals("LYRICS200"))
{
filePointer = file.getFilePointer();
}
else
{
return false;
}
}
// read the 6 bytes for the length of the tag
filePointer -= (9 + 6);
file.seek(filePointer);
file.read(buffer, 0, 6);
lyricSize = Integer.parseInt(new String(buffer, 0, 6));
// read the lyrics begin tag if it exists.
file.seek(filePointer - lyricSize);
file.read(buffer, 0, 11);
lyricStart = new String(buffer, 0, 11);
return lyricStart.equals("LYRICSBEGIN");
| private int | seekSize(java.nio.ByteBuffer byteBuffer)TODO
/*
byte[] buffer = new byte[11];
String lyricEnd = "";
long filePointer = 0;
// check right before the ID3 1.0 tag for the lyrics tag
file.seek(file.length() - 128 - 9);
file.read(buffer, 0, 9);
lyricEnd = new String(buffer, 0, 9);
if (lyricEnd.equals("LYRICS200"))
{
filePointer = 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);
lyricEnd = new String(buffer, 0, 9);
if (lyricEnd.equals("LYRICS200"))
{
filePointer = file.getFilePointer();
}
else
{
return -1;
}
}
// read the 6 bytes for the length of the tag
filePointer -= (9 + 6);
file.seek(filePointer);
file.read(buffer, 0, 6);
return Integer.parseInt(new String(buffer, 0, 6));
*/
return -1;
| public void | setField(Lyrics3v2Field field)
fieldMap.put(field.getIdentifier(), field);
| public java.lang.String | toString()
Iterator<Lyrics3v2Field> iterator = fieldMap.values().iterator();
Lyrics3v2Field field;
String str = getIdentifier() + " " + this.getSize() + "\n";
while (iterator.hasNext())
{
field = iterator.next();
str += (field.toString() + "\n");
}
return str;
| public void | updateField(java.lang.String identifier)
Lyrics3v2Field lyrField;
if (identifier.equals("IND"))
{
boolean lyricsPresent = fieldMap.containsKey("LYR");
boolean timeStampPresent = false;
if (lyricsPresent)
{
lyrField = fieldMap.get("LYR");
FieldFrameBodyLYR lyrBody = (FieldFrameBodyLYR) lyrField.getBody();
timeStampPresent = lyrBody.hasTimeStamp();
}
lyrField = new Lyrics3v2Field(new FieldFrameBodyIND(lyricsPresent, timeStampPresent));
setField(lyrField);
}
| public void | write(java.io.RandomAccessFile file)
int offset = 0;
long size;
long filePointer;
byte[] buffer = new byte[6 + 9];
String str;
Lyrics3v2Field field;
Iterator<Lyrics3v2Field> iterator;
ID3v1Tag id3v1tag;
new ID3v1Tag();
id3v1tag = null;
delete(file);
file.seek(file.length());
filePointer = file.getFilePointer();
str = "LYRICSBEGIN";
for (int i = 0; i < str.length(); i++)
{
buffer[i] = (byte) str.charAt(i);
}
file.write(buffer, 0, str.length());
// IND needs to go first. lets createField/update it and write it first.
updateField("IND");
field = fieldMap.get("IND");
field.write(file);
iterator = fieldMap.values().iterator();
while (iterator.hasNext())
{
field = iterator.next();
String id = field.getIdentifier();
boolean save = TagOptionSingleton.getInstance().getLyrics3SaveField(id);
if ((!id.equals("IND")) && save)
{
field.write(file);
}
}
size = file.getFilePointer() - filePointer;
if (this.getSize() != size)
{
//logger.config("Lyrics3v2 size didn't match up while writing.");
//logger.config("this.getsize() = " + this.getSize());
//logger.config("size (filePointer) = " + size);
}
str = Long.toString(size);
for (int i = 0; i < (6 - str.length()); i++)
{
buffer[i] = (byte) '0";
}
offset += (6 - str.length());
for (int i = 0; i < str.length(); i++)
{
buffer[i + offset] = (byte) str.charAt(i);
}
offset += str.length();
str = "LYRICS200";
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);
}
|
|