helliker.id3
Class ID3v2Frame

java.lang.Object
  extended byhelliker.id3.ID3v2Frame

public class ID3v2Frame
extends java.lang.Object


Field Summary
private  boolean compressed
           
private  int dataLength
           
private  java.lang.String[] ENC_TYPES
           
private  byte encrType
           
private  boolean encrypted
           
private  boolean fileAlterDiscard
           
private  int FRAME_FLAGS_SIZE
           
private  int FRAME_HEAD_SIZE
           
private  byte[] frameData
           
private  byte group
           
private  boolean grouped
           
private  java.lang.String id
           
private  boolean lengthIndicator
           
private  int MAX_EXTRA_DATA
           
private  boolean readOnly
           
private  boolean tagAlterDiscard
           
private  boolean unsynchronised
           
 
Constructor Summary
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)
          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.
 
Method Summary
private  boolean checkDefaultFileAlterDiscard()
          Returns true if this frame should have the file alter preservation bit set by default.
 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.
private  java.lang.String getDecodedString(byte[] b, int eIndex, int offset)
          Converts the byte array into a string based on the type of encoding.
 boolean getEncrypted()
          Returns true if this frame is encrypted
 byte getEncryptionType()
          If encrypted, this returns the encryption method byte.
private  byte[] getExtraDataBytes()
          A helper function for the getFrameBytes function that returns an array of all the data contained in any extra fields that may be present in this frame.
 boolean getFileAlterDiscard()
          Returns true if the file alter preservation bit has been set.
private  byte[] getFlagBytes()
          A helper function for the getFrameBytes method that processes the info in the frame and returns the 2 byte array of flags to be added to the header.
 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
 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.
private  void parseData(byte[] data)
          Pulls out extra information inserted in the frame data depending on what flags are set.
private  void parseFlags(byte[] flags)
          Read the information from the flags array.
 void setFrameData(byte[] newData)
          Set the data for this frame.
 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
 

Field Detail

FRAME_HEAD_SIZE

private final int FRAME_HEAD_SIZE
See Also:
Constant Field Values

FRAME_FLAGS_SIZE

private final int FRAME_FLAGS_SIZE
See Also:
Constant Field Values

MAX_EXTRA_DATA

private final int MAX_EXTRA_DATA
See Also:
Constant Field Values

ENC_TYPES

private final java.lang.String[] ENC_TYPES

id

private java.lang.String id

tagAlterDiscard

private boolean tagAlterDiscard

fileAlterDiscard

private boolean fileAlterDiscard

readOnly

private boolean readOnly

grouped

private boolean grouped

compressed

private boolean compressed

encrypted

private boolean encrypted

unsynchronised

private boolean unsynchronised

lengthIndicator

private boolean lengthIndicator

group

private byte group

encrType

private byte encrType

dataLength

private int dataLength

frameData

private byte[] frameData
Constructor Detail

ID3v2Frame

public ID3v2Frame(java.lang.String id,
                  byte[] flags,
                  byte[] data)
           throws ID3v2FormatException
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

ID3v2Frame

public ID3v2Frame(java.lang.String id,
                  byte[] data)
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

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)
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
Method Detail

checkDefaultFileAlterDiscard

private boolean checkDefaultFileAlterDiscard()
Returns true if this frame should have the file alter preservation bit set by default.

Returns:
true if the file alter preservation should be set by default

parseFlags

private void parseFlags(byte[] flags)
                 throws ID3v2FormatException
Read the information from the flags array.

Parameters:
flags - the flags found in the frame header
Throws:
ID3v2FormatException - if an error occurs

parseData

private void parseData(byte[] data)
Pulls out extra information inserted in the frame data depending on what flags are set.

Parameters:
data - the frame data

getFrameData

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

Returns:
the data for this frame

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

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

getFlagBytes

private byte[] getFlagBytes()
A helper function for the getFrameBytes method that processes the info in the frame and returns the 2 byte array of flags to be added to the header.

Returns:
a value of type 'byte[]'

getExtraDataBytes

private byte[] getExtraDataBytes()
A helper function for the getFrameBytes function that returns an array of all the data contained in any extra fields that may be present in this frame. This includes the group, the encryption type, and the length indicator. The length of the array returned is variable length.

Returns:
an array of bytes containing the extra data fields in the frame

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

getDecodedString

private java.lang.String getDecodedString(byte[] b,
                                          int eIndex,
                                          int offset)
                                   throws java.io.UnsupportedEncodingException
Converts the byte array into a string based on the type of encoding. One byte in the array should contain the type of encoding. Where it is located is specifed by the eIndex parameter. If an invalid type of encoding is found, the empty string is returned.

Parameters:
b - the array of bytes to convert/decode
eIndex - the index in the array where the encoding type resides
offset - where in the array to start the string
Returns:
the decoded string or an empty string if the encoding is wrong
Throws:
java.io.UnsupportedEncodingException - if an error occurs

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.

Returns:
a string representation of this object


Copyright © 2004 NeurosDBM Dev Team All Rights Reserved.