com.beaglebuddy.id3.v24.frame_body

## Class ID3v24FrameBody

- java.lang.Object
- - com.beaglebuddy.id3.v24.frame_body.ID3v24FrameBodyUtility
  - - com.beaglebuddy.id3.v24.frame_body.ID3v24FrameBody

- Direct Known Subclasses:
    ID3v24FrameBodyAttachedPicture, ID3v24FrameBodyAudioEncryption, ID3v24FrameBodyAudioSeekPointIndex, ID3v24FrameBodyComments, ID3v24FrameBodyCommercial, ID3v24FrameBodyEncryptionMethodRegistration, ID3v24FrameBodyEqualization, ID3v24FrameBodyEventTimingCodes, ID3v24FrameBodyGeneralEncapsulatedObject, ID3v24FrameBodyGroupIdentificationRegistration, ID3v24FrameBodyInvolvedPeopleList, ID3v24FrameBodyLinkedInformation, ID3v24FrameBodyMPEGLocationLookupTable, ID3v24FrameBodyMusicCDIdentifier, ID3v24FrameBodyOwnership, ID3v24FrameBodyPlayCounter, ID3v24FrameBodyPopularimeter, ID3v24FrameBodyPositionSynchronization, ID3v24FrameBodyPrivate, ID3v24FrameBodyRecommendedBufferSize, ID3v24FrameBodyRelativeVolumeAdjustment, ID3v24FrameBodyReverb, ID3v24FrameBodySeek, ID3v24FrameBodySignature, ID3v24FrameBodySynchronizedLyricsText, ID3v24FrameBodySynchronizedTempoCodes, ID3v24FrameBodyTermsOfUse, ID3v24FrameBodyTextInformation, ID3v24FrameBodyUniqueFileIdentifier, ID3v24FrameBodyUnsynchronizedLyrics, ID3v24FrameBodyURLLink, ID3v24FrameBodyUserDefinedTextInformation, ID3v24FrameBodyUserDefinedURLLink

      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.

  See Also:
    ID3 tag version 2.4.0 standard, wikipedia history of ID3 tags

- - ### Field Summary

    Fields
    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.

    - ### Fields inherited from class com.beaglebuddy.id3.v24.frame_body.ID3v24FrameBodyUtility

      `nextNullTerminatorIndex, nullTerminatorIndex`

  - ### Constructor Summary

    Constructors
    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.

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class com.beaglebuddy.id3.v24.frame_body.ID3v24FrameBodyUtility

      `bytesToInt, bytesToShort, bytesToSynchsafeInt, bytesToSynchsafeShort, formateDate, getNextNullTerminator, hex, hex, intToBytes, pad, pricesToString, shortToBytes, stringToBytes, synchsafeIntToBytes`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### buffer

          protected byte[] buffer

    - #### dirty

          protected boolean dirty

      indicates whether the raw byte buffer contains the same values as the the frame body's data members. ie, whether a user has modified the frame body's values, and if so, whether have been saved back to the raw byte buffer.

    - #### frameType

          protected FrameType frameType

      the frame type which is used by derived classes when creating error messages.

  - ### Constructor Detail

    - #### ID3v24FrameBody

          public ID3v24FrameBody(FrameType frameType)

      This constructor is called when creating a new frame body.
      Parameters:
        `frameType` - the type of ID3v2.4 frame that is to be created.

    - #### ID3v24FrameBody

          public ID3v24FrameBody(java.io.InputStream inputStream,
                         FrameType frameType,
                         int frameBodySize)
                          throws java.io.IOException

      constructor. called when reading in an existing frame body from an .mp3 file.
      Parameters:
        `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.
      Throws:
        `java.io.IOException` - if there is an error while reading in the frame body.

    - #### ID3v24FrameBody

          public ID3v24FrameBody(java.io.InputStream inputStream,
                         java.lang.String invalidFrameId,
                         int frameBodySize)
                          throws java.io.IOException

      constructor. called when reading in an existing invalid frame body from an .mp3 file. this allows invalid frames to be read in and skipped over in an attempt to read in the remaining valid frames.
      Parameters:
        `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.
      Throws:
        `java.io.IOException` - if there is an error while reading in the frame body.

  - ### Method Detail

    - #### getFrameType

          public FrameType getFrameType()

      gets the frame body's ID3v2.4 type.
      Returns:
        the frame body's ID3v2.4 type.

    - #### getNextNullTerminator

          protected int getNextNullTerminator(int startingFrom,
                                  Encoding encoding)

      finds the next null terminating character according to the character encoding in the raw data stream.
      Parameters:
        `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).
      Returns:
        the index of the next null terminator in the data.

    - #### getSize

          public int getSize()

      gets the size (in bytes) of the frame body.
      Returns:
        the size (in bytes) of the frame body.

    - #### isDirty

          public boolean isDirty()

      gets whether any value(s) in the frame's body have been modified.
      Returns:
        whether any value(s) in the frame's body have been modified.

    - #### parse

          public void parse()
                     throws java.lang.IllegalArgumentException

      parses the raw bytes of the frame body and stores the parsed values in the frame body's fields.
      Throws:
        `java.lang.IllegalArgumentException` - if an invalid value is detected while parsing the frame body's raw bytes.

    - #### setBuffer

          public void setBuffer()

      If the frame body's values have been modified, then resize the raw byte buffer and store the new values there. When finished, the dirty flag is reset to indicate that the buffer is up to date, and the frame is now ready to be saved to the .mp3 file.

      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.

    - #### save

          public void save(java.io.OutputStream outputStream)
                    throws java.lang.IllegalStateException,
                           java.io.IOException

      save the frame body to the .mp3 file.
      Parameters:
        `outputStream` - an output stream pointing to where the next frame body should be written.
      Throws:
        `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.

    - #### save

          public void save(java.io.RandomAccessFile file)
                    throws java.lang.IllegalStateException,
                           java.io.IOException

      save the frame body to the .mp3 file.
      Parameters:
        `file` - a random access file pointing to where the next frame body should be written.
      Throws:
        `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.