private ByteBuffer writeHeaderToBuffer(int padding,int size) throws IOException {
  extended=false;
  experimental=false;
  crcDataFlag=false;
  ByteBuffer headerBuffer=ByteBuffer.allocate(TAG_HEADER_LENGTH + TAG_EXT_HEADER_LENGTH + TAG_EXT_HEADER_CRC_LENGTH);
  headerBuffer.put(TAG_ID);
  headerBuffer.put(getMajorVersion());
  headerBuffer.put(getRevision());
  byte flagsByte=0;
  if (isUnsynchronization()) {
    flagsByte|=MASK_V23_UNSYNCHRONIZATION;
  }
  if (extended) {
    flagsByte|=MASK_V23_EXTENDED_HEADER;
  }
  if (experimental) {
    flagsByte|=MASK_V23_EXPERIMENTAL;
  }
  headerBuffer.put(flagsByte);
  int additionalHeaderSize=0;
  if (extended) {
    additionalHeaderSize+=TAG_EXT_HEADER_LENGTH;
    if (crcDataFlag) {
      additionalHeaderSize+=TAG_EXT_HEADER_CRC_LENGTH;
    }
  }
  headerBuffer.put(ID3SyncSafeInteger.valueToBuffer(padding + size + additionalHeaderSize));
  if (extended) {
    byte extFlagsByte1=0;
    byte extFlagsByte2=0;
    if (crcDataFlag) {
      headerBuffer.putInt(TAG_EXT_HEADER_DATA_LENGTH + TAG_EXT_HEADER_CRC_LENGTH);
      extFlagsByte1|=MASK_V23_CRC_DATA_PRESENT;
      headerBuffer.put(extFlagsByte1);
      headerBuffer.put(extFlagsByte2);
      headerBuffer.putInt(paddingSize);
      headerBuffer.putInt(crc32);
    }
 else {
      headerBuffer.putInt(TAG_EXT_HEADER_DATA_LENGTH);
      headerBuffer.put(extFlagsByte1);
      headerBuffer.put(extFlagsByte2);
      headerBuffer.putInt(padding);
    }
  }
  headerBuffer.flip();
  return headerBuffer;
}

private ByteBuffer writeHeaderToBuffer ( int padding , int size ) throws IOException { extended = false ; experimental = false ; crcDataFlag = false ; ByteBuffer headerBuffer = ByteBuffer . allocate ( TAG_HEADER_LENGTH + TAG_EXT_HEADER_LENGTH + TAG_EXT_HEADER_CRC_LENGTH ) ; headerBuffer . put ( TAG_ID ) ; headerBuffer . put ( getMajorVersion ( ) ) ; headerBuffer . put ( getRevision ( ) ) ; byte flagsByte = 0 ; if ( isUnsynchronization ( ) ) { flagsByte |= MASK_V23_UNSYNCHRONIZATION ; } if ( extended ) { flagsByte |= MASK_V23_EXTENDED_HEADER ; } if ( experimental ) { flagsByte |= MASK_V23_EXPERIMENTAL ; } headerBuffer . put ( flagsByte ) ; int additionalHeaderSize = 0 ; if ( extended ) { additionalHeaderSize += TAG_EXT_HEADER_LENGTH ; if ( crcDataFlag ) { additionalHeaderSize += TAG_EXT_HEADER_CRC_LENGTH ; } } headerBuffer . put ( ID3SyncSafeInteger . valueToBuffer ( padding + size + additionalHeaderSize ) ) ; if ( extended ) { byte extFlagsByte1 = 0 ; byte extFlagsByte2 = 0 ; if ( crcDataFlag ) { headerBuffer . putInt ( TAG_EXT_HEADER_DATA_LENGTH + TAG_EXT_HEADER_CRC_LENGTH ) ; extFlagsByte1 |= MASK_V23_CRC_DATA_PRESENT ; headerBuffer . put ( extFlagsByte1 ) ; headerBuffer . put ( extFlagsByte2 ) ; headerBuffer . putInt ( paddingSize ) ; headerBuffer . putInt ( crc32 ) ; } else { headerBuffer . putInt ( TAG_EXT_HEADER_DATA_LENGTH ) ; headerBuffer . put ( extFlagsByte1 ) ; headerBuffer . put ( extFlagsByte2 ) ; headerBuffer . putInt ( padding ) ; } } headerBuffer . flip ( ) ; return headerBuffer ; }
write the id3 header to the bytebuffer . todo calculate the cyc data check todo reintroduce extended header
