org.jaudiotagger.tag.id3
Class ID3SyncSafeInteger

java.lang.Object
  extended by org.jaudiotagger.tag.id3.ID3SyncSafeInteger

public class ID3SyncSafeInteger
extends java.lang.Object

Peforms encoding/decoding of an syncsafe integer

Syncsafe integers are used for the size in the tag header of v23 and v24 tags, and in the frame size in the frame header of v24 frames.

In some parts of the tag it is inconvenient to use the unsychronisation scheme because the size of unsynchronised data is not known in advance, which is particularly problematic with size descriptors. The solution in ID3v2 is to use synchsafe integers, in which there can never be any false synchs. 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.

Example:

255 (%11111111) encoded as a 16 bit synchsafe integer is 383 (%00000001 01111111).


Field Summary
static int INTEGRAL_SIZE
           
static int MAX_SAFE_SIZE
          Sizes equal or smaller than this are the same whether held as sync safe integer or normal integer so it doesnt matter.
 
Constructor Summary
ID3SyncSafeInteger()
           
 
Method Summary
private static int bufferToValue(byte[] buffer)
          Read syncsafe value from byteArray in format specified in spec and convert to int.
protected static int bufferToValue(java.nio.ByteBuffer buffer)
          Read syncsafe value from buffer in format specified in spec and convert to int.
protected static boolean isBufferEmpty(byte[] buffer)
          Checks if the buffer just contains zeros

This can be used to identify when accessing padding of a tag

protected static boolean isBufferNotSyncSafe(java.nio.ByteBuffer buffer)
          Is buffer holding a value that is definently not syncsafe

We cannot guarantee a buffer is holding a syncsafe integer but there are some checks we can do to show that it definently is not.

protected static byte[] valueToBuffer(int size)
          Convert int value to syncsafe value held in bytearray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTEGRAL_SIZE

public static final int INTEGRAL_SIZE
See Also:
Constant Field Values

MAX_SAFE_SIZE

public static final int MAX_SAFE_SIZE
Sizes equal or smaller than this are the same whether held as sync safe integer or normal integer so it doesnt matter.

See Also:
Constant Field Values
Constructor Detail

ID3SyncSafeInteger

public ID3SyncSafeInteger()
Method Detail

bufferToValue

private static int bufferToValue(byte[] buffer)
Read syncsafe value from byteArray in format specified in spec and convert to int.

Parameters:
buffer - syncsafe integer
Returns:
decoded int

bufferToValue

protected static int bufferToValue(java.nio.ByteBuffer buffer)
Read syncsafe value from buffer in format specified in spec and convert to int.

The buffers position is moved to just after the location of the syscsafe integer

Parameters:
buffer - syncsafe integer
Returns:
decoded int

isBufferNotSyncSafe

protected static boolean isBufferNotSyncSafe(java.nio.ByteBuffer buffer)
Is buffer holding a value that is definently not syncsafe

We cannot guarantee a buffer is holding a syncsafe integer but there are some checks we can do to show that it definently is not.

The buffer is NOT moved after reading.

This function is useful for reading ID3v24 frames created in iTunes because iTunes does not use syncsafe integers in its frames.

Parameters:
buffer -
Returns:
true if this buffer is definently not holding a syncsafe integer

isBufferEmpty

protected static boolean isBufferEmpty(byte[] buffer)
Checks if the buffer just contains zeros

This can be used to identify when accessing padding of a tag

Parameters:
buffer -
Returns:
true if buffer only contains zeros

valueToBuffer

protected static byte[] valueToBuffer(int size)
Convert int value to syncsafe value held in bytearray

Parameters:
size -
Returns:
buffer syncsafe integer