public class ID3v24FrameBody extends ID3v24FrameBodyUtility
This is the base class for all ID3v2.4 frame bodies. Although ID3v2.4 defines 83 different types of frames, many groups of frame bodies have the
same fields, and thus are implemented by a single class. For example, there are 45 text information frames, and thus the corresponding frame bodies are implemented in one
ID3v24FrameBodyTextInformation
class. Similarly, there are 8 url link frames, but all are implemented using the ID3v24FrameBodyURLLink
class.
Each frame body has a raw, binary buffer, which is nothing more than a byte array. This is what is read in from the .mp3 file. This byte array holds all of the values for a
given frame body. When a frame body is read in from an .mp3 file (more accurately, from the ID3v2.4 tag in the .mp3 file), this binary buffer is parsed and the values are stored in
the frame body's data members. Users are then free to change the values of the frame body's data members. When the user is finished making changes, he must call the setBuffer()
method in order to write all the frame body's data members back to the binary buffer, before calling save(OutputStream)
. However, you should not be invoking these methods,
as calling MP3.save()
will handle all of this for you.
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buffer |
protected boolean |
dirty
indicates whether the raw byte buffer contains the same values as the the frame body's data members.
|
protected FrameType |
frameType
the frame type which is used by derived classes when creating error messages.
|
nextNullTerminatorIndex, nullTerminatorIndex
Constructor and Description |
---|
ID3v24FrameBody(FrameType frameType)
This constructor is called when creating a new frame body.
|
ID3v24FrameBody(java.io.InputStream inputStream,
FrameType frameType,
int frameBodySize)
constructor.
|
ID3v24FrameBody(java.io.InputStream inputStream,
java.lang.String invalidFrameId,
int frameBodySize)
constructor.
|
Modifier and Type | Method and Description |
---|---|
FrameType |
getFrameType()
gets the frame body's ID3v2.4 type.
|
protected int |
getNextNullTerminator(int startingFrom,
Encoding encoding)
finds the next null terminating character according to the character encoding in the raw data stream.
|
int |
getSize()
gets the size (in bytes) of the frame body.
|
boolean |
isDirty()
gets whether any value(s) in the frame's body have been modified.
|
void |
parse()
parses the raw bytes of the frame body and stores the parsed values in the frame body's fields.
|
void |
save(java.io.OutputStream outputStream)
save the frame body to the .mp3 file.
|
void |
save(java.io.RandomAccessFile file)
save the frame body to the .mp3 file.
|
void |
setBuffer()
If the frame body's values have been modified, then resize the raw byte buffer and store the new values there.
|
getNextNullTerminator, pricesToString, stringToBytes
bytesToInt, bytesToInt, bytesToShort, bytesToShort, bytesToSynchsafeInt, bytesToSynchsafeShort, formateDate, hex, hex, hex, intToBytes, littleEndianBytesToInt, pad, shortToBytes, synchsafeIntToBytes
protected byte[] buffer
protected boolean dirty
protected FrameType frameType
public ID3v24FrameBody(FrameType frameType)
frameType
- the type of ID3v2.4 frame that is to be created.public ID3v24FrameBody(java.io.InputStream inputStream, FrameType frameType, int frameBodySize) throws java.io.IOException
inputStream
- input stream pointing to a frame body in the .mp3 file.frameType
- the type of ID3v2.4 frame to create.frameBodySize
- size (in bytes) of the frame's body.java.io.IOException
- if there is an error while reading in the frame body.public ID3v24FrameBody(java.io.InputStream inputStream, java.lang.String invalidFrameId, int frameBodySize) throws java.io.IOException
inputStream
- input stream pointing to a frame body in the .mp3 file.invalidFrameId
- the id of the invalid frame.frameBodySize
- size (in bytes) of the frame's body.java.io.IOException
- if there is an error while reading in the frame body.public FrameType getFrameType()
protected int getNextNullTerminator(int startingFrom, Encoding encoding)
startingFrom
- the index at which to start searching from in the buffer.encoding
- the character set used to encode the string (and hence determine the null terminating character).
public int getSize()
public boolean isDirty()
public void parse() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if an invalid value is detected while parsing the frame body's raw bytes.public void setBuffer()
this method should be abstract. However, the ID3v24Frame constructor needs to be able to instanitate instances of a frame body in the case where it encounters an invalid frame. For this reason, this method was made concrete, and simply throws an exception if it is ever called in this base class. However, derived classes implement this method to correctly update the raw byte buffer.
public void save(java.io.OutputStream outputStream) throws java.lang.IllegalStateException, java.io.IOException
outputStream
- an output stream pointing to where the next frame body should be written.java.lang.IllegalStateException
- If the any of the frame body's values have been modified, then the setBuffer() method must be called prior to calling save()
in order to save the modifications to the frame body's raw byte buffer.java.io.IOException
- if an error occurs while writing the raw byte data in the buffer to the file.public void save(java.io.RandomAccessFile file) throws java.lang.IllegalStateException, java.io.IOException
file
- a random access file pointing to where the next frame body should be written.java.lang.IllegalStateException
- If the any of the frame body's values have been modified, then the setBuffer() method must be called prior to calling save()
in order to save the modifications to the frame body's raw byte buffer.java.io.IOException
- if an error occurs while writing the raw byte data in the buffer to the file.