pgbennett.id3
Class ID3v2Frame

java.lang.Object
  extended by pgbennett.id3.ID3v2Frame

public class ID3v2Frame
extends java.lang.Object

This class holds the information found in an id3v2 frame. At this point at least, the information in the tag header is read-only and can only be set set in the constructor. This is for simplicity's sake. This object doesn't automatically unsynchronise, encrypt, or compress the data.

Version History
1.3.1 - 2002.1023 by gruni
-Made Sourcecode compliant to the Sun CodingConventions
1.3 - 2002/01/13 by helliker
-Added isEmpty method
1.2 - 2001/10/19 by helliker
-All set for release.


Constructor Summary
ID3v2Frame(ID3v2Picture pic)
          Create and ID3v2 frame with the specified id and data.
ID3v2Frame(java.lang.String id, byte[] data)
          Create and ID3v2 frame with the specified id and data.
ID3v2Frame(java.lang.String id, byte[] data, boolean tagAlterDiscard, boolean fileAlterDiscard, boolean readOnly, boolean grouped, boolean compressed, boolean encrypted, boolean unsynchronised, boolean lengthIndicator)
          Create an ID3v2Frame with the specified id, data, and flags set.
ID3v2Frame(java.lang.String id, byte[] flags, byte[] data, int majorVersion)
          Create an ID3v2Frame with a specified id, a byte array containing the frame header flags, and a byte array containing the data for this frame.
ID3v2Frame(java.lang.String id, java.lang.String lang, java.lang.String desc, java.lang.String data)
           
 
Method Summary
static byte[] encodeString(java.lang.String source, byte[] encodingB)
           
 boolean getCompressed()
          Returns true if this frame is compressed
 int getDataLength()
          If a length indicator has been added, the length of the data is returned.
 java.lang.String getDataString()
          If possible, this method attempts to convert textual part of the data into a string.
 boolean getEncrypted()
          Returns true if this frame is encrypted
 byte getEncryptionType()
          If encrypted, this returns the encryption method byte.
 java.lang.String getExtendedId()
          Get extended id for cases where two occurrences of the same id are allowed with different descriptors (e.g.
 boolean getFileAlterDiscard()
          Returns true if the file alter preservation bit has been set.
 byte[] getFrameBytes()
          Returns a byte array representation of this frame that can be written to a file.
 byte[] getFrameData()
          Returns the data for this frame
 int getFrameLength()
          Return the length of this frame in bytes, including the header.
 byte getGroup()
          Returns the group identifier if added.
 boolean getGrouped()
          Returns true if this frame is a part of a group
 boolean getLengthIndicator()
          Returns true if this frame has a length indicator added
 ID3v2Picture getPicture()
          Get Picture data for APIC frame
 boolean getReadOnly()
          Returns true if this frame is read only
 boolean getTagAlterDiscard()
          Returns true if the tag alter preservation bit has been set.
 boolean getUnsynchronised()
          Returns true if this frame is unsynchronised
 boolean isEmpty()
          Returns true if there is no data in the frame.
 void setFrameData(byte[] newData)
          Set the data for this frame.
 void setPicture(ID3v2Picture pic)
           
 java.lang.String toString()
          Return a string representation of this object that contains all the information contained within it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ID3v2Frame

public ID3v2Frame(java.lang.String id,
                  byte[] flags,
                  byte[] data,
                  int majorVersion)
           throws ID3v2FormatException,
                  java.io.UnsupportedEncodingException
Create an ID3v2Frame with a specified id, a byte array containing the frame header flags, and a byte array containing the data for this frame.

Parameters:
id - the id of this frame
flags - the flags found in the header of the frame (2 bytes)
data - the data found in this frame
Throws:
ID3v2FormatException - if an error occurs
java.io.UnsupportedEncodingException

ID3v2Frame

public ID3v2Frame(java.lang.String id,
                  byte[] data)
           throws java.io.UnsupportedEncodingException
Create and ID3v2 frame with the specified id and data. All the flag bits are set to false.

Parameters:
id - the id of this frame
data - the data for this frame
Throws:
java.io.UnsupportedEncodingException

ID3v2Frame

public ID3v2Frame(ID3v2Picture pic)
           throws java.io.UnsupportedEncodingException
Create and ID3v2 frame with the specified id and data. All the flag bits are set to false.

Parameters:
id - the id of this frame
data - the data for this frame
Throws:
java.io.UnsupportedEncodingException

ID3v2Frame

public ID3v2Frame(java.lang.String id,
                  java.lang.String lang,
                  java.lang.String desc,
                  java.lang.String data)
           throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

ID3v2Frame

public ID3v2Frame(java.lang.String id,
                  byte[] data,
                  boolean tagAlterDiscard,
                  boolean fileAlterDiscard,
                  boolean readOnly,
                  boolean grouped,
                  boolean compressed,
                  boolean encrypted,
                  boolean unsynchronised,
                  boolean lengthIndicator)
           throws java.io.UnsupportedEncodingException
Create an ID3v2Frame with the specified id, data, and flags set. It is expected that the corresponing data for the flags that require extra data is found in the data array in the standard place.

Parameters:
id - the id for this frame
data - the data for this frame
tagAlterDiscard - the tag alter preservation flag
fileAlterDiscard - the file alter preservation flag
readOnly - the read only flag
grouped - the grouping identity flag
compressed - the compression flag
encrypted - the encryption flag
unsynchronised - the unsynchronisation flag
lengthIndicator - the data length indicator flag
Throws:
java.io.UnsupportedEncodingException
Method Detail

encodeString

public static byte[] encodeString(java.lang.String source,
                                  byte[] encodingB)
                           throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

setFrameData

public void setFrameData(byte[] newData)
Set the data for this frame. This does nothing if this frame is read only.

Parameters:
newData - a byte array containing the new data

getFrameData

public byte[] getFrameData()
Returns the data for this frame

Returns:
the data for this frame

getFrameLength

public int getFrameLength()
Return the length of this frame in bytes, including the header.

Returns:
the length of this frame

getFrameBytes

public byte[] getFrameBytes()
Returns a byte array representation of this frame that can be written to a file. Includes the header and data.

Returns:
a binary representation of this frame to be written to a file

getTagAlterDiscard

public boolean getTagAlterDiscard()
Returns true if the tag alter preservation bit has been set. If set then the frame should be discarded if it is altered and the id is unknown.

Returns:
true if the tag alter preservation bit has been set

getFileAlterDiscard

public boolean getFileAlterDiscard()
Returns true if the file alter preservation bit has been set. If set then the frame should be discarded if the file is altered and the id is unknown.

Returns:
true if the file alter preservation bit has been set

getReadOnly

public boolean getReadOnly()
Returns true if this frame is read only

Returns:
true if this frame is read only

getGrouped

public boolean getGrouped()
Returns true if this frame is a part of a group

Returns:
true if this frame is a part of a group

getCompressed

public boolean getCompressed()
Returns true if this frame is compressed

Returns:
true if this frame is compressed

getEncrypted

public boolean getEncrypted()
Returns true if this frame is encrypted

Returns:
true if this frame is encrypted

getUnsynchronised

public boolean getUnsynchronised()
Returns true if this frame is unsynchronised

Returns:
true if this frame is unsynchronised

getLengthIndicator

public boolean getLengthIndicator()
Returns true if this frame has a length indicator added

Returns:
true if this frame has a length indicator added

getGroup

public byte getGroup()
Returns the group identifier if added. Otherwise the null byte is returned.

Returns:
the groupd identifier if added, null byte otherwise

getEncryptionType

public byte getEncryptionType()
If encrypted, this returns the encryption method byte. If it is not encrypted, the null byte is returned.

Returns:
the encryption method if set and the null byte if not

getDataLength

public int getDataLength()
If a length indicator has been added, the length of the data is returned. Otherwise -1 is returned.

Returns:
the length of the data if a length indicator is present or -1

getDataString

public java.lang.String getDataString()
                               throws ID3v2FormatException
If possible, this method attempts to convert textual part of the data into a string. If this frame does not contain textual information, an empty string is returned.

Returns:
the textual portion of the data in this frame
Throws:
ID3v2FormatException - if an error occurs

isEmpty

public boolean isEmpty()
Returns true if there is no data in the frame.

Returns:
true if there is no data in the frame

toString

public java.lang.String toString()
Return a string representation of this object that contains all the information contained within it.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object

getPicture

public ID3v2Picture getPicture()
Get Picture data for APIC frame


setPicture

public void setPicture(ID3v2Picture pic)
                throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

getExtendedId

public java.lang.String getExtendedId()
Get extended id for cases where two occurrences of the same id are allowed with different descriptors (e.g. COMM)