com.beaglebuddy.id3.v23.frame_body

## Class ID3v23FrameBodyUtility

- java.lang.Object
- - com.beaglebuddy.id3.v23.frame_body.ID3v23FrameBodyUtility

- Direct Known Subclasses:
    ID3v23FrameBody

      public class ID3v23FrameBodyUtility
      extends java.lang.Object

  Base class for the body of ID3V2.3 frames. This class is simply a collection of utility methods and is not a frame body type.
  See Also:
    ID3 tag version 2.3.0 standard, wikipedia history of ID3 tags

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `nextNullTerminatorIndex`
    `protected int` | `nullTerminatorIndex`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ID3v23FrameBodyUtility()` default constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `bytesToInt(byte[] buffer, int index)` converts the 4 bytes starting at the specified index to an integer.
    `static short` | `bytesToShort(byte[] buffer, int index)` converts the 2 bytes starting at the specified index to a short.
    `static int` | `bytesToSynchsafeInt(byte[] buffer, int index)` converts the 4 bytes starting at the specified index to a synchsafe integer.
    `static short` | `bytesToSynchsafeShort(byte[] buffer, int index)` converts the 2 bytes starting at the specified index to a synchsafe short.
    `static java.lang.String` | `formateDate(java.util.Date date)` formats a date as YYYYMMDD.
    `static int` | `getNextNullTerminator(byte[] buffer, int startingFrom, Encoding encoding)` finds the next null terminating character in the raw data stream according to the specified character encoding.
    `static java.lang.String` | `hex(byte data)` formats a single byte as a 2 digit hex value, ie, 0xbb, where 0 < b < F. example: decimal: 12 -> hex: 0C example: decimal: 178 -> hex: B2
    `static java.lang.String` | `hex(byte[] data, int indent)` formats raw binary byte data as a sequence of bytes in the format 0xbb 0xbb ...
    `static byte[]` | `intToBytes(int n)` converts an integer value to a 4 byte array.
    `static java.lang.String` | `pad(int numSpaces)` gets a string consisting of the specified number of blank spaces which can be used for padding (left or right) in order to format some output (ie, make columns line up, etc).
    `static java.lang.String` | `pricesToString(java.util.List<Price> prices)` convert a list of prices to a string, with each price separated by the "/" character. example: USD0.99/EUR1.00/GBP0.65
    `static byte[]` | `shortToBytes(int n)` converts a short value to a 2 byte array.
    `static byte[]` | `stringToBytes(Encoding encoding, java.lang.String string)` converts a String to a byte array using a specified character set encoding.
    `static byte[]` | `synchsafeIntToBytes(int n)` converts a synchsafe integer value to a 4 byte array.

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

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

- - ### Field Detail

    - #### nullTerminatorIndex

          protected int nullTerminatorIndex

    - #### nextNullTerminatorIndex

          protected int nextNullTerminatorIndex

  - ### Constructor Detail

    - #### ID3v23FrameBodyUtility

          public ID3v23FrameBodyUtility()

      default constructor.

  - ### Method Detail

    - #### formateDate

          public static java.lang.String formateDate(java.util.Date date)

      formats a date as YYYYMMDD.
      Parameters:
        `date` - the date to format. If null, then the today's date is used.
      Returns:
        the specified date formatted as YYYYMMDD.

    - #### getNextNullTerminator

          public static int getNextNullTerminator(byte[] buffer,
                                  int startingFrom,
                                  Encoding encoding)

      finds the next null terminating character in the raw data stream according to the specified character encoding. A null character is represented as a single 0x00 byte in some character encodings and as two bytes 0x00 0x00 in others.
      Parameters:
        `buffer` - the raw binary bytes in which to find the next null terminator character.
        `startingFrom` - the index at which to start searching from in the data.
        `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.

    - #### stringToBytes

          public static byte[] stringToBytes(Encoding encoding,
                             java.lang.String string)

      converts a String to a byte array using a specified character set encoding. The String class has a getBytes() method, but that method does not include a null terminator in the byte array that it returns. This method does.
      Parameters:
        `encoding` - the encoding to use when converting the string to a byte array.
        `string` - the string to be converted to a byte array.
      Returns:
        a byte array holding the string value in the specified encoding with null terminating bytes.

    - #### hex

          public static java.lang.String hex(byte data)

      formats a single byte as a 2 digit hex value, ie, 0xbb, where 0 < b < F.
      example: decimal: 12 -> hex: 0C
      example: decimal: 178 -> hex: B2
      Parameters:
        `data` - byte data whose value will be converted to hex.
      Returns:
        the hex representation of a byte.

    - #### hex

          public static java.lang.String hex(byte[] data,
                             int indent)

      formats raw binary byte data as a sequence of bytes in the format 0xbb 0xbb ... with 16 bytes per line.
      Parameters:
        `data` - raw binary data to be printed.
        `indent` - number of spaces to indent each line of output before displaying the hex bytes.
      Returns:
        a string representation of the binary data as hexadecimal bytes.

    - #### pad

          public static java.lang.String pad(int numSpaces)

      gets a string consisting of the specified number of blank spaces which can be used for padding (left or right) in order to format some output (ie, make columns line up, etc).
      Parameters:
        `numSpaces` - number of spaces to return.
      Returns:
        a string of spaces.

    - #### pricesToString

          public static java.lang.String pricesToString(java.util.List<Price> prices)

      convert a list of prices to a string, with each price separated by the "/" character.
      example: USD0.99/EUR1.00/GBP0.65
      Parameters:
        `prices` - list of prices.
      Returns:
        a string representation of the list of price(s).

    - #### intToBytes

          public static byte[] intToBytes(int n)

      converts an integer value to a 4 byte array.
      Parameters:
        `n` - the integer value to be converted to a byte array.
      Returns:
        a 4 byte array holding the integer value.

    - #### bytesToInt

          public static int bytesToInt(byte[] buffer,
                       int index)

      converts the 4 bytes starting at the specified index to an integer.
      Parameters:
        `buffer` - the byte array from which the next four sequential bytes will be converted to an integer.
        `index` - specifies that the bytes at index, index + 1, index +2, and index + 3 will be converted to an integer.
      Returns:
        the integer value obtained from starting at the specified index in the byte array and converting the next four sequential bytes.

    - #### bytesToSynchsafeInt

          public static int bytesToSynchsafeInt(byte[] buffer,
                                int index)

      converts the 4 bytes starting at the specified index to a synchsafe integer.
      Parameters:
        `buffer` - the byte array from which the next four sequential bytes will be converted to a synchsafe integer.
        `index` - specifies that the bytes at index, index + 1, index +2, and index + 3 will be converted to a synchsafe integer.
      Returns:
        the synchsafe integer value obtained from starting at the specified index in the byte array and converting the next four sequential bytes.
      See Also:
        "http://stackoverflow.com/questions/5223025/why-are-there-synchsafe-integer"

    - #### synchsafeIntToBytes

          public static byte[] synchsafeIntToBytes(int n)

      converts a synchsafe integer value to a 4 byte array. Synchsafe integers are integers that keep its highest bit (bit 7) zeroed, making seven bits out of eight available. Thus a 32 bit synchsafe integer can store 28 bits of information.
      Parameters:
        `n` - the synchsafe integer value to be converted to a byte array.
      Returns:
        a 4 byte array holding the synchsafe integer value.

    - #### shortToBytes

          public static byte[] shortToBytes(int n)

      converts a short value to a 2 byte array.
      Parameters:
        `n` - the short value to be converted to a byte array.
      Returns:
        a 2 byte array holding the short value.

    - #### bytesToShort

          public static short bytesToShort(byte[] buffer,
                           int index)

      converts the 2 bytes starting at the specified index to a short.
      Parameters:
        `buffer` - the byte array from which the next to sequential bytes will be converted to a short.
        `index` - specifies that the bytes at index and at index + 1 will be converted to a short.
      Returns:
        the short value obtained from starting at the specified index in the byte array and converting the next two sequential bytes.

    - #### bytesToSynchsafeShort

          public static short bytesToSynchsafeShort(byte[] buffer,
                                    int index)

      converts the 2 bytes starting at the specified index to a synchsafe short.
      Parameters:
        `buffer` - the byte array from which the next to sequential bytes will be converted to a synchsafe short.
        `index` - specifies that the bytes at index and at index + 1 will be converted to a synchsafe short.
      Returns:
        the synchsafe short value obtained from starting at the specified index in the byte array and converting the next two sequential bytes.